RoomVC: Use cells with encryption badge only if needed in order to recover horizontal white space.

This commit is contained in:
SBiOSoftWhare
2020-02-06 18:46:32 +01:00
parent 2fc2431c4c
commit 490f45c9de
11 changed files with 46 additions and 77 deletions
@@ -29,12 +29,11 @@ extern NSString *const kRoomEncryptedDataBubbleCellTapOnEncryptionIcon;
@interface RoomEncryptedDataBubbleCell : NSObject
/**
Return the icon displayed in front an event in an encrypted room .
Return the icon displayed in front of an event in an encrypted room if needed.
@param event the event.
@param session the matrix session
@param event the bubble component.
*/
+ (UIImage*)encryptionIconForEvent:(MXEvent*)event andSession:(MXSession*)session;
+ (UIImage*)encryptionIconForBubbleComponent:(MXKRoomBubbleComponent *)bubbleComponent;
/**
Set the encryption status icon in front of each bubble component.
@@ -21,53 +21,14 @@ NSString *const kRoomEncryptedDataBubbleCellTapOnEncryptionIcon = @"kRoomEncrypt
@implementation RoomEncryptedDataBubbleCell
+ (UIImage*)encryptionIconForEvent:(MXEvent*)event andSession:(MXSession*)session
+ (UIImage*)encryptionIconForBubbleComponent:(MXKRoomBubbleComponent *)bubbleComponent
{
MXRoom *room = [session roomWithRoomId:event.roomId];
BOOL isRoomEncrypted = room.summary.isEncrypted && session.crypto;
if (!isRoomEncrypted)
if (!bubbleComponent.showEncryptionBadge)
{
return nil;
}
NSString *encryptionIconName;
UIImage* encryptionIcon;
if (!event.isEncrypted)
{
if (event.isLocalEvent
|| event.isState
|| event.contentHasBeenEdited) // Local echo for an edit is clear but uses a true event id, the one of the edited event
{
encryptionIconName = nil;
}
else
{
encryptionIconName = @"encryption_warning";
}
}
else if (event.decryptionError)
{
encryptionIconName = @"encryption_warning";
}
else if (event.sender)
{
MXUserTrustLevel *userTrustLevel = [session.crypto trustLevelForUser:event.sender];
MXDeviceInfo *deviceInfo = [session.crypto eventDeviceInfo:event];
if (userTrustLevel.isVerified && !deviceInfo.trustLevel.isVerified)
{
encryptionIconName = @"encryption_warning";
}
}
if (encryptionIconName)
{
encryptionIcon = [UIImage imageNamed:encryptionIconName];
}
return encryptionIcon;
return [UIImage imageNamed:@"encryption_warning"];
}
+ (void)addEncryptionStatusFromBubbleData:(MXKRoomBubbleCellData *)bubbleData inContainerView:(UIView *)containerView
@@ -93,8 +54,8 @@ NSString *const kRoomEncryptedDataBubbleCellTapOnEncryptionIcon = @"kRoomEncrypt
{
continue;
}
UIImage *icon = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession];
UIImage *icon = [[self class] encryptionIconForBubbleComponent:component];
if (icon)
{
@@ -111,7 +72,7 @@ NSString *const kRoomEncryptedDataBubbleCellTapOnEncryptionIcon = @"kRoomEncrypt
encryptStatusImageView.tag = componentIndex;
[containerView addSubview:encryptStatusImageView];
}
}
}
}
@@ -43,7 +43,7 @@
MXKRoomBubbleComponent *component = bubbleData.bubbleComponents.firstObject;
if (component)
{
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession];
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForBubbleComponent:component];
}
}
}
@@ -45,7 +45,7 @@
MXKRoomBubbleComponent *component = bubbleData.bubbleComponents.firstObject;
if (component)
{
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession];
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForBubbleComponent:component];
}
}
}
@@ -43,7 +43,7 @@
MXKRoomBubbleComponent *component = bubbleData.bubbleComponents.firstObject;
if (component)
{
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession];
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForBubbleComponent:component];
}
}
}
@@ -43,7 +43,7 @@
MXKRoomBubbleComponent *component = bubbleData.bubbleComponents.firstObject;
if (component)
{
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession];
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForBubbleComponent:component];
}
}
}
@@ -63,4 +63,4 @@
}
}
@end
@end
@@ -43,7 +43,7 @@
MXKRoomBubbleComponent *component = bubbleData.bubbleComponents.firstObject;
if (component)
{
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession];
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForBubbleComponent:component];
}
}
}
@@ -62,4 +62,5 @@
}
}
}
@end
@end
@@ -43,7 +43,7 @@
MXKRoomBubbleComponent *component = bubbleData.bubbleComponents.firstObject;
if (component)
{
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession];
self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForBubbleComponent:component];
}
}
}
@@ -62,4 +62,4 @@
}
}
}
@end
@end