Decorate events decrypted with untrusted sessions

This commit is contained in:
Andy Uhnak
2022-09-28 17:02:45 +01:00
parent b817955e90
commit 726aa29323
18 changed files with 105 additions and 25 deletions
@@ -73,7 +73,7 @@
}
}
_showEncryptionBadge = [self shouldShowWarningBadgeForEvent:event roomState:(MXRoomState*)roomState session:session];
_encryptionDecoration = [self encryptionDecorationForEvent:event roomState:(MXRoomState*)roomState session:session];
[self updateLinkWithRoomState:roomState];
@@ -116,7 +116,7 @@
andLatestRoomState:latestRoomState
error:&error];
_showEncryptionBadge = [self shouldShowWarningBadgeForEvent:event roomState:roomState session:session];
_encryptionDecoration = [self encryptionDecorationForEvent:event roomState:roomState session:session];
[self updateLinkWithRoomState:roomState];
}
@@ -167,24 +167,24 @@
self.link = url;
}
- (BOOL)shouldShowWarningBadgeForEvent:(MXEvent*)event roomState:(MXRoomState*)roomState session:(MXSession*)session
- (EventEncryptionDecoration)encryptionDecorationForEvent:(MXEvent*)event roomState:(MXRoomState*)roomState session:(MXSession*)session
{
// Warning badges are unnecessary in unencrypted rooms
if (!roomState.isEncrypted)
{
return NO;
return EventEncryptionDecorationNone;
}
// Not all events are encrypted (e.g. state/reactions/redactions) and we only have encrypted cell subclasses for messages and attachments.
if (event.eventType != MXEventTypeRoomMessage && !event.isMediaAttachment)
{
return NO;
return EventEncryptionDecorationNone;
}
// Always show a warning badge if there was a decryption error.
if (event.decryptionError)
{
return YES;
return EventEncryptionDecorationDecryptionError;
}
// Unencrypted message events should show a warning unless they're pending local echoes
@@ -193,10 +193,10 @@
if (event.isLocalEvent
|| event.contentHasBeenEdited) // Local echo for an edit is clear but uses a true event id, the one of the edited event
{
return NO;
return EventEncryptionDecorationNone;
}
return YES;
return EventEncryptionDecorationNotEncrypted;
}
// The encryption is in a good state.
@@ -208,12 +208,17 @@
if (userTrustLevel.isVerified && !deviceInfo.trustLevel.isVerified)
{
return YES;
return EventEncryptionDecorationUntrustedDevice;
}
}
if (event.isUntrusted)
{
return EventEncryptionDecorationUnsafeKey;
}
// Everything was fine
return NO;
return EventEncryptionDecorationNone;
}
@end