Skip to content

Commit

Permalink
WIP: log OMEMO device changes in history
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichAltheide committed Aug 4, 2024
1 parent 06a3a5e commit 23e2b33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Monal/Classes/MLOMEMO.m
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,23 @@ -(void) queryOMEMODevices:(NSString*) jid withSubscribe:(BOOL) subscribe
[self retriggerKeyTransportElementsForJid:jid]; //retrigger queued key transport elements for this jid (if any)
$$

-(void) postOMEMOMessageForUser:(NSString*) jid withMessage:(NSString*) omemoMessage
{
if(![[DataLayer sharedInstance] isContactInList:jid forAccount:self.account.accountNo]) {
[[DataLayer sharedInstance] addContact:jid forAccount:self.account.accountNo nickname:nil];
}
NSString* newMessageID = [[NSUUID UUID] UUIDString];
NSNumber* historyId = [[DataLayer sharedInstance] addMessageHistoryTo:jid forAccount:self.account.accountNo withMessage:omemoMessage actuallyFrom:jid withId:newMessageID encrypted:NO messageType:kMessageTypeStatus mimeType:nil size:nil];

MLMessage* message = [[DataLayer sharedInstance] messageForHistoryID:historyId];
MLContact* contact = [MLContact createContactFromJid:jid andAccountNo:self.account.accountNo];
[[MLNotificationQueue currentQueue] postNotificationName:kMonalNewMessageNotice object:self.account userInfo:@{
@"message": message,
@"showAlert": @(NO),
@"contact": contact,
}];
}

-(void) processOMEMODevices:(NSSet<NSNumber*>*) receivedDevices from:(NSString*) source
{
DDLogVerbose(@"Processing omemo devices from %@: %@", source, receivedDevices);
Expand Down Expand Up @@ -459,6 +476,7 @@ -(void) processOMEMODevices:(NSSet<NSNumber*>*) receivedDevices from:(NSString*)
if(![source isEqualToString:self.account.connectionProperties.identity.jid] || deviceId.unsignedIntValue != self.monalSignalStore.deviceid)
{
DDLogDebug(@"Removing device %@", deviceId);
[self postOMEMOMessageForUser:source withMessage:[NSString stringWithFormat:NSLocalizedString(@"OMEMO: Device %@ is now inactive, because it is no longer advertised by your contact", @"OMEMO warning shown inside chat view"), deviceId]];
SignalAddress* address = [[SignalAddress alloc] initWithName:source deviceId:deviceId.unsignedIntValue];
[self.monalSignalStore markDeviceAsDeleted:address];
}
Expand Down Expand Up @@ -614,6 +632,8 @@ -(void) queryOMEMOBundleFrom:(NSString*) jid andDevice:(NSNumber*) deviceid
}
else
{
[self postOMEMOMessageForUser:jid withMessage:[NSString stringWithFormat:NSLocalizedString(@"OMEMO: Detected new device with id: %@", @"OMEMO warning shown inside chat view"), rid]];

//check that a corresponding buddy exists -> prevent foreign key errors
MLXMLNode* receivedKeys = data[@"current"];
if(receivedKeys == nil && data.count == 1)
Expand Down
3 changes: 2 additions & 1 deletion Monal/localization/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1358,11 +1358,12 @@
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="A Status message would go here. That is correct, a status message. " textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="15o-hp-DgI">
<rect key="frame" x="10" y="9" width="1004" height="34"/>
<color key="backgroundColor" systemColor="systemYellowColor"/>
<constraints>
<constraint firstAttribute="height" constant="33.670000000000002" id="0ag-YG-RGy"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="14"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
<attributedString key="userComments">
<fragment content="#bc-ignore!"/>
Expand Down

0 comments on commit 23e2b33

Please sign in to comment.