Skip to content

Commit

Permalink
Simplify event encryption decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed Mar 27, 2023
1 parent 7dafa67 commit 39fdbc9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
29 changes: 10 additions & 19 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ - (EventEncryptionDecoration)encryptionDecorationForEvent:(MXEvent*)event roomSt
// Always show a warning badge if there was a decryption error.
if (event.decryptionError)
{
return EventEncryptionDecorationDecryptionError;
return EventEncryptionDecorationRed;
}

// Unencrypted message events should show a warning unless they're pending local echoes
Expand All @@ -199,29 +199,20 @@ - (EventEncryptionDecoration)encryptionDecorationForEvent:(MXEvent*)event roomSt
return EventEncryptionDecorationNone;
}

return EventEncryptionDecorationNotEncrypted;
return EventEncryptionDecorationRed;
}

// The encryption is in a good state.
// Only show a warning badge if there are trust issues.
if (event.sender)
// Only show a warning badge if there are decryption trust issues.
switch (event.decryptionDecoration.color)
{
MXUserTrustLevel *userTrustLevel = [session.crypto trustLevelForUser:event.sender];
MXDeviceInfo *deviceInfo = [session.crypto eventDeviceInfo:event];

if (userTrustLevel.isVerified && !deviceInfo.trustLevel.isVerified)
{
return EventEncryptionDecorationUntrustedDevice;
}
}

if (event.isUntrusted)
{
return EventEncryptionDecorationUnsafeKey;
case MXEventDecryptionDecorationColorRed:
return EventEncryptionDecorationRed;
case MXEventDecryptionDecorationColorGrey:
return EventEncryptionDecorationGrey;
case MXEventDecryptionDecorationColorNone:
return EventEncryptionDecorationNone;
}

// Everything was fine
return EventEncryptionDecorationNone;
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ - (void)updateTextViewText
NSString *claimedKey = _mxEvent.keysClaimed[@"ed25519"];
NSString *algorithm = _mxEvent.wireContent[@"algorithm"];
NSString *sessionId = _mxEvent.wireContent[@"session_id"];
NSString *untrusted = _mxEvent.isUntrusted ? [VectorL10n roomEventEncryptionInfoKeyAuthenticityNotGuaranteed] : [VectorL10n userVerificationSessionsListSessionTrusted];
NSString *safetyMessage = _mxEvent.decryptionDecoration.message;
if (!safetyMessage)
{
// Use default copy if none is provided by the decryption decoration
safetyMessage = _mxEvent.decryptionDecoration.color != MXEventDecryptionDecorationColorNone ? [VectorL10n roomEventEncryptionInfoKeyAuthenticityNotGuaranteed] : [VectorL10n userVerificationSessionsListSessionTrusted];
}

NSString *decryptionError;
if (_mxEvent.decryptionError)
Expand All @@ -218,7 +223,8 @@ - (void)updateTextViewText
}

[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:[VectorL10n roomEventEncryptionInfoEventUserId] attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
initWithString:[VectorL10n roomEventEncryptionInfoEventUserId]
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:senderId
Expand Down Expand Up @@ -284,7 +290,7 @@ - (void)updateTextViewText
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:untrusted
initWithString:safetyMessage
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
Expand Down Expand Up @@ -368,20 +374,23 @@ - (void)updateTextViewText
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];

[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:[VectorL10n roomEventEncryptionInfoDeviceId] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
initWithString:[VectorL10n roomEventEncryptionInfoDeviceId]
attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:deviceId
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];

[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:[VectorL10n roomEventEncryptionInfoDeviceVerification] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
initWithString:[VectorL10n roomEventEncryptionInfoDeviceVerification]
attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
[deviceInformationString appendAttributedString:verification];
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];

[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:[VectorL10n roomEventEncryptionInfoDeviceFingerprint] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
initWithString:[VectorL10n roomEventEncryptionInfoDeviceFingerprint]
attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:fingerprint
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
Expand All @@ -392,7 +401,8 @@ - (void)updateTextViewText
{
// Unknown device
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:[VectorL10n roomEventEncryptionInfoDeviceUnknown] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont italicSystemFontOfSize:14]}]];
initWithString:[VectorL10n roomEventEncryptionInfoDeviceUnknown]
attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont italicSystemFontOfSize:14]}]];
}

[textViewAttributedString appendAttributedString:deviceInformationString];
Expand Down Expand Up @@ -462,7 +472,8 @@ - (IBAction)onButtonPressed:(id)sender
{
// Prompt user
NSMutableAttributedString *textViewAttributedString = [[NSMutableAttributedString alloc]
initWithString:[VectorL10n roomEventEncryptionVerifyTitle] attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
initWithString:[VectorL10n roomEventEncryptionVerifyTitle]
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];

NSString *message = [VectorL10n roomEventEncryptionVerifyMessage:_mxDeviceInfo.displayName :_mxDeviceInfo.deviceId :_mxDeviceInfo.fingerprint];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#ifndef EventEncryptionDecoration_h
#define EventEncryptionDecoration_h

/**
Decoration used alongside encrypted events
*/
typedef NS_ENUM(NSUInteger, EventEncryptionDecoration)
{
EventEncryptionDecorationNone,
EventEncryptionDecorationUnsafeKey,
EventEncryptionDecorationDecryptionError,
EventEncryptionDecorationNotEncrypted,
EventEncryptionDecorationUntrustedDevice
EventEncryptionDecorationGrey,
EventEncryptionDecorationRed
};


#endif /* EventEncryptionDecoration_h */
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ + (UIImage*)encryptionIconForBubbleComponent:(MXKRoomBubbleComponent *)bubbleCom
switch (bubbleComponent.encryptionDecoration) {
case EventEncryptionDecorationNone:
return nil;
case EventEncryptionDecorationUnsafeKey:
case EventEncryptionDecorationGrey:
return AssetImages.encryptionUntrusted.image;
case EventEncryptionDecorationDecryptionError:
case EventEncryptionDecorationNotEncrypted:
case EventEncryptionDecorationUntrustedDevice:
case EventEncryptionDecorationRed:
return AssetImages.encryptionWarning.image;
default:
return nil;
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7440.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Encryption: Simplify event encryption decoration

0 comments on commit 39fdbc9

Please sign in to comment.