Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room decoration: Use shields instead of padlocks #2962

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@ Improvements:
* ON/OFF Cross-signing development in a Lab setting (#2855).
* RoomVC: Update encryption decoration with shields (#2934, #2930, #2906).
* Settings: Remove "End-to-End Encryption" from the LABS section (#2941).
* Room decoration: Use shields instead of padlocks (#2906).

Changes in 0.10.4 (2019-12-11)
===============================================
Expand Down
1 change: 1 addition & 0 deletions Riot/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 266,7 @@ (void)initialize
// Set the App Group identifier.
MXSDKOptions *sdkOptions = [MXSDKOptions sharedInstance];
sdkOptions.applicationGroupIdentifier = @"group.im.vector";
sdkOptions.computeE2ERoomSummaryTrust = YES;

// Redirect NSLogs to files only if we are not debugging
if (!isatty(STDERR_FILENO))
Expand Down
18 changes: 18 additions & 0 deletions Riot/Categories/MXRoomSummary Riot.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,17 @@

#import <MatrixKit/MatrixKit.h>

/**
RoomEncryptionTrustLevel represents the trust level in an encrypted room.
*/
typedef NS_ENUM(NSUInteger, RoomEncryptionTrustLevel) {
RoomEncryptionTrustLevelTrusted,
RoomEncryptionTrustLevelWarning,
RoomEncryptionTrustLevelNormal,
RoomEncryptionTrustLevelUnknown
};


/**
Define a `MXRoomSummary` category at Riot level.
*/
Expand All @@ -32,4 43,11 @@
*/
- (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView;

/**
Get the trust level in the room.

@return the trust level.
*/
- (RoomEncryptionTrustLevel)roomEncryptionTrustLevel;

@end
27 changes: 27 additions & 0 deletions Riot/Categories/MXRoomSummary Riot.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 47,31 @@ - (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView
mxkImageView.contentMode = UIViewContentModeScaleAspectFill;
}

- (RoomEncryptionTrustLevel)roomEncryptionTrustLevel
{
RoomEncryptionTrustLevel roomEncryptionTrustLevel = RoomEncryptionTrustLevelUnknown;
if (self.trust)
{
double trustedDevicesPercentage = self.trust.trustedDevicesProgress.fractionCompleted;

if (trustedDevicesPercentage >= 1.0
|| self.trust.trustedDevicesProgress.totalUnitCount == 0)
{
roomEncryptionTrustLevel = RoomEncryptionTrustLevelTrusted;
}
else if (trustedDevicesPercentage == 0.0)
{
roomEncryptionTrustLevel = RoomEncryptionTrustLevelNormal;
}
else
{
roomEncryptionTrustLevel = RoomEncryptionTrustLevelWarning;
}

roomEncryptionTrustLevel = roomEncryptionTrustLevel;
}

return roomEncryptionTrustLevel;
}

@end
38 changes: 37 additions & 1 deletion Riot/Modules/Common/Recents/Views/RecentTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 137,15 @@ - (void)render:(MXKCellData *)cellData

self.directRoomBorderView.hidden = !roomCellData.roomSummary.room.isDirect;

self.encryptedRoomIcon.hidden = !roomCellData.roomSummary.isEncrypted;
if (roomCellData.roomSummary.isEncrypted)
{
self.encryptedRoomIcon.hidden = NO;
self.encryptedRoomIcon.image = [self shieldImageForTrustLevel:roomCellData.roomSummary.roomEncryptionTrustLevel];
}
else
{
self.encryptedRoomIcon.hidden = YES;
}

[roomCellData.roomSummary setRoomAvatarImageIn:self.roomAvatar];
}
Expand All @@ -153,4 161,32 @@ (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)m
return 74;
}

- (UIImage*)shieldImageForTrustLevel:(RoomEncryptionTrustLevel)roomEncryptionTrustLevel
{
UIImage *shieldImage;

NSString *encryptionIconName;
switch (roomEncryptionTrustLevel)
{
case RoomEncryptionTrustLevelWarning:
encryptionIconName = @"encryption_warning";
break;
case RoomEncryptionTrustLevelNormal:
encryptionIconName = @"encryption_normal";
break;
case RoomEncryptionTrustLevelTrusted:
encryptionIconName = @"encryption_trusted";
break;
case RoomEncryptionTrustLevelUnknown:
encryptionIconName = @"encryption_normal";
break;
}

if (encryptionIconName)
{
shieldImage = [UIImage imageNamed:encryptionIconName];
}
return shieldImage;
}

@end
38 changes: 37 additions & 1 deletion Riot/Modules/Home/Views/RoomCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 159,15 @@ - (void)render:(MXKCellData *)cellData

self.directRoomBorderView.hidden = !roomCellData.roomSummary.room.isDirect;

self.encryptedRoomIcon.hidden = !roomCellData.roomSummary.isEncrypted;
if (roomCellData.roomSummary.isEncrypted)
{
self.encryptedRoomIcon.hidden = NO;
self.encryptedRoomIcon.image = [self shieldImageForTrustLevel:roomCellData.roomSummary.roomEncryptionTrustLevel];
}
else
{
self.encryptedRoomIcon.hidden = YES;
}

[roomCellData.roomSummary setRoomAvatarImageIn:self.roomAvatar];
}
Expand Down Expand Up @@ -207,5 215,33 @@ - (NSString*)roomId
return nil;
}

- (UIImage*)shieldImageForTrustLevel:(RoomEncryptionTrustLevel)roomEncryptionTrustLevel
{
UIImage *shieldImage;

NSString *encryptionIconName;
switch (roomEncryptionTrustLevel)
{
case RoomEncryptionTrustLevelWarning:
encryptionIconName = @"encryption_warning";
break;
case RoomEncryptionTrustLevelNormal:
encryptionIconName = @"encryption_normal";
break;
case RoomEncryptionTrustLevelTrusted:
encryptionIconName = @"encryption_trusted";
break;
case RoomEncryptionTrustLevelUnknown:
encryptionIconName = @"encryption_normal";
break;
}

if (encryptionIconName)
{
shieldImage = [UIImage imageNamed:encryptionIconName];
}
return shieldImage;
}

@end

10 changes: 1 addition & 9 deletions Riot/Modules/Room/DataSources/RoomDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 19,7 @@

#import "WidgetManager.h"

/**
RoomEncryptionTrustLevel represents the room members trust level in an encrypted room.
*/
typedef NS_ENUM(NSUInteger, RoomEncryptionTrustLevel) {
RoomEncryptionTrustLevelTrusted,
RoomEncryptionTrustLevelWarning,
RoomEncryptionTrustLevelNormal,
RoomEncryptionTrustLevelUnknown
};
#import "MXRoomSummary Riot.h"

@protocol RoomDataSourceDelegate;

Expand Down
76 changes: 9 additions & 67 deletions Riot/Modules/Room/DataSources/RoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 112,7 @@ - (void)finalizeInitialization
NSLog(@"[MXKRoomDataSource] finalizeRoomDataSource: Cannot retrieve all room members");
}];
}

if (self.room.summary.isEncrypted)
{
[self fetchEncryptionTrustedLevel];
Expand Down Expand Up @@ -193,84 193,26 @@ - (void)setNeedsUpdateAdditionalContentHeightForCellData:(id<MXKRoomBubbleCellDa

- (void)registerTrustLevelDidChangeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceInfoTrustLevelDidChange:) name:MXDeviceInfoTrustLevelDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(crossSigningInfoTrustLevelDidChange:) name:MXCrossSigningInfoTrustLevelDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(roomSummaryDidChange:) name:kMXRoomSummaryDidChangeNotification object:self.room.summary];
}

- (void)deviceInfoTrustLevelDidChange:(NSNotification*)notification
{
MXDeviceInfo *deviceInfo = notification.object;

NSString *userId = deviceInfo.userId;

if (userId)
{
[self encryptionTrustLevelDidChangeRelatedToUserId:userId forceDownload:NO];
}
}

- (void)crossSigningInfoTrustLevelDidChange:(NSNotification*)notification
- (void)roomSummaryDidChange:(NSNotification*)notification
{
MXCrossSigningInfo *crossSigningInfo = notification.object;

NSString *userId = crossSigningInfo.userId;

if (userId)
if (!self.room.summary.isEncrypted)
{
[self encryptionTrustLevelDidChangeRelatedToUserId:userId forceDownload:NO];
return;
}

[self fetchEncryptionTrustedLevel];
}

- (void)fetchEncryptionTrustedLevel
{
[self encryptionTrustLevelDidChangeRelatedToUserId:self.mxSession.myUser.userId forceDownload:YES];
self.encryptionTrustLevel = self.room.summary.roomEncryptionTrustLevel;
[self.roomDataSourceDelegate roomDataSource:self didUpdateEncryptionTrustLevel:self.encryptionTrustLevel];
}

- (void)encryptionTrustLevelDidChangeRelatedToUserId:(NSString*)userId forceDownload:(BOOL)forceDownload
{
if (!self.room.summary.isEncrypted)
{
return;
}

[self.room members:^(MXRoomMembers *roomMembers) {
MXRoomMember *roomMember = [roomMembers memberWithUserId:userId];

// If user belongs to the room refresh the trust level
if (roomMember)
{
[self.room membersTrustLevelSummaryWithForceDownload:forceDownload success:^(MXUsersTrustLevelSummary *usersTrustLevelSummary) {

RoomEncryptionTrustLevel roomEncryptionTrustLevel;

double trustedDevicesPercentage = usersTrustLevelSummary.trustedDevicesProgress.fractionCompleted;

if (trustedDevicesPercentage >= 1.0
|| usersTrustLevelSummary.trustedDevicesProgress.totalUnitCount == 0)
{
roomEncryptionTrustLevel = RoomEncryptionTrustLevelTrusted;
}
else if (trustedDevicesPercentage == 0.0)
{
roomEncryptionTrustLevel = RoomEncryptionTrustLevelNormal;
}
else
{
roomEncryptionTrustLevel = RoomEncryptionTrustLevelWarning;
}

self.encryptionTrustLevel = roomEncryptionTrustLevel;
[self.roomDataSourceDelegate roomDataSource:self didUpdateEncryptionTrustLevel:roomEncryptionTrustLevel];

} failure:^(NSError *error) {
NSLog(@"[RoomDataSource] trustLevelDidChangeRelatedToUserId fails to retrieve room members trusted progress");
}];
}

} failure:^(NSError *error) {
NSLog(@"[RoomDataSource] trustLevelDidChangeRelatedToUserId fails to retrieve room members");
}];
}

#pragma mark -

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 71,15 @@ - (void)render:(MXKCellData *)cellData

self.directRoomBorderView.hidden = !roomCellData.roomSummary.isDirect;

self.encryptedRoomIcon.hidden = !roomCellData.roomSummary.isEncrypted;
if (roomCellData.roomSummary.isEncrypted)
{
self.encryptedRoomIcon.hidden = NO;
self.encryptedRoomIcon.image = [self shieldImageForTrustLevel:roomCellData.roomSummary.roomEncryptionTrustLevel];
}
else
{
self.encryptedRoomIcon.hidden = YES;
}
}
}

Expand All @@ -80,4 88,32 @@ (CGFloat)cellHeight
return 74;
}

- (UIImage*)shieldImageForTrustLevel:(RoomEncryptionTrustLevel)roomEncryptionTrustLevel
{
UIImage *shieldImage;

NSString *encryptionIconName;
switch (roomEncryptionTrustLevel)
{
case RoomEncryptionTrustLevelWarning:
encryptionIconName = @"encryption_warning";
break;
case RoomEncryptionTrustLevelNormal:
encryptionIconName = @"encryption_normal";
break;
case RoomEncryptionTrustLevelTrusted:
encryptionIconName = @"encryption_trusted";
break;
case RoomEncryptionTrustLevelUnknown:
encryptionIconName = @"encryption_normal";
break;
}

if (encryptionIconName)
{
shieldImage = [UIImage imageNamed:encryptionIconName];
}
return shieldImage;
}

@end