diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index e38abb761..2702657e3 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -341,7 +341,7 @@ CGFloat leftMargin = RoomBubbleCellLayout.reactionsViewLeftMargin; - if (self.room.summary.isEncrypted) + if (roomBubbleCellData.containsBubbleComponentWithEncryptionBadge) { leftMargin+= RoomBubbleCellLayout.encryptedContentLeftMargin; } diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 7da406e14..25eb328e2 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -2095,13 +2095,21 @@ - (Class)cellViewClassForCellData:(MXKCellData*)cellData { Class cellViewClass = nil; - BOOL isEncryptedRoom = self.roomDataSource.room.summary.isEncrypted; + BOOL showEncryptionBadge = NO; // Sanity check if ([cellData conformsToProtocol:@protocol(MXKRoomBubbleCellDataStoring)]) { id bubbleData = (id)cellData; + MXKRoomBubbleCellData *roomBubbleCellData; + + if ([bubbleData isKindOfClass:MXKRoomBubbleCellData.class]) + { + roomBubbleCellData = (MXKRoomBubbleCellData*)bubbleData; + showEncryptionBadge = roomBubbleCellData.containsBubbleComponentWithEncryptionBadge; + } + // Select the suitable table view cell class, by considering first the empty bubble cell. if (bubbleData.hasNoDisplay) { @@ -2159,15 +2167,15 @@ } else if (bubbleData.isPaginationFirstBubble) { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.class : RoomIncomingAttachmentWithPaginationTitleBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.class : RoomIncomingAttachmentWithPaginationTitleBubbleCell.class; } else if (bubbleData.shouldHideSenderInformation) { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedAttachmentWithoutSenderInfoBubbleCell.class : RoomIncomingAttachmentWithoutSenderInfoBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedAttachmentWithoutSenderInfoBubbleCell.class : RoomIncomingAttachmentWithoutSenderInfoBubbleCell.class; } else { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedAttachmentBubbleCell.class : RoomIncomingAttachmentBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedAttachmentBubbleCell.class : RoomIncomingAttachmentBubbleCell.class; } } else @@ -2176,24 +2184,24 @@ { if (bubbleData.shouldHideSenderName) { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class : RoomIncomingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class : RoomIncomingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class; } else { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedTextMsgWithPaginationTitleBubbleCell.class : RoomIncomingTextMsgWithPaginationTitleBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedTextMsgWithPaginationTitleBubbleCell.class : RoomIncomingTextMsgWithPaginationTitleBubbleCell.class; } } else if (bubbleData.shouldHideSenderInformation) { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedTextMsgWithoutSenderInfoBubbleCell.class : RoomIncomingTextMsgWithoutSenderInfoBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedTextMsgWithoutSenderInfoBubbleCell.class : RoomIncomingTextMsgWithoutSenderInfoBubbleCell.class; } else if (bubbleData.shouldHideSenderName) { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedTextMsgWithoutSenderNameBubbleCell.class : RoomIncomingTextMsgWithoutSenderNameBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedTextMsgWithoutSenderNameBubbleCell.class : RoomIncomingTextMsgWithoutSenderNameBubbleCell.class; } else { - cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedTextMsgBubbleCell.class : RoomIncomingTextMsgBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomIncomingEncryptedTextMsgBubbleCell.class : RoomIncomingTextMsgBubbleCell.class; } } } @@ -2209,15 +2217,15 @@ } else if (bubbleData.isPaginationFirstBubble) { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedAttachmentWithPaginationTitleBubbleCell.class :RoomOutgoingAttachmentWithPaginationTitleBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedAttachmentWithPaginationTitleBubbleCell.class :RoomOutgoingAttachmentWithPaginationTitleBubbleCell.class; } else if (bubbleData.shouldHideSenderInformation) { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedAttachmentWithoutSenderInfoBubbleCell.class : RoomOutgoingAttachmentWithoutSenderInfoBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedAttachmentWithoutSenderInfoBubbleCell.class : RoomOutgoingAttachmentWithoutSenderInfoBubbleCell.class; } else { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedAttachmentBubbleCell.class : RoomOutgoingAttachmentBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedAttachmentBubbleCell.class : RoomOutgoingAttachmentBubbleCell.class; } } else @@ -2226,24 +2234,24 @@ { if (bubbleData.shouldHideSenderName) { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class : RoomOutgoingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class : RoomOutgoingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.class; } else { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedTextMsgWithPaginationTitleBubbleCell.class : RoomOutgoingTextMsgWithPaginationTitleBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedTextMsgWithPaginationTitleBubbleCell.class : RoomOutgoingTextMsgWithPaginationTitleBubbleCell.class; } } else if (bubbleData.shouldHideSenderInformation) { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedTextMsgWithoutSenderInfoBubbleCell.class :RoomOutgoingTextMsgWithoutSenderInfoBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedTextMsgWithoutSenderInfoBubbleCell.class :RoomOutgoingTextMsgWithoutSenderInfoBubbleCell.class; } else if (bubbleData.shouldHideSenderName) { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedTextMsgWithoutSenderNameBubbleCell.class : RoomOutgoingTextMsgWithoutSenderNameBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedTextMsgWithoutSenderNameBubbleCell.class : RoomOutgoingTextMsgWithoutSenderNameBubbleCell.class; } else { - cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedTextMsgBubbleCell.class : RoomOutgoingTextMsgBubbleCell.class; + cellViewClass = showEncryptionBadge ? RoomOutgoingEncryptedTextMsgBubbleCell.class : RoomOutgoingTextMsgBubbleCell.class; } } } diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.h b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.h index 4db36a8bf..a97402465 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.h +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.h @@ -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. diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m index 240045041..6958e3ed5 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m @@ -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]; - } + } } } diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentBubbleCell.m index e46cba929..3139b418c 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentBubbleCell.m @@ -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]; } } } diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.m index af76485f5..b0e2b5e76 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.m @@ -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]; } } } diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithoutSenderInfoBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithoutSenderInfoBubbleCell.m index a127189ee..b8be790cb 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithoutSenderInfoBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomIncomingEncryptedAttachmentWithoutSenderInfoBubbleCell.m @@ -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]; } } } diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentBubbleCell.m index 6b0e0c6de..c5dfe21a1 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentBubbleCell.m @@ -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 \ No newline at end of file +@end diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithPaginationTitleBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithPaginationTitleBubbleCell.m index 9def7d21f..ac6afe709 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithPaginationTitleBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithPaginationTitleBubbleCell.m @@ -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 \ No newline at end of file + +@end diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithoutSenderInfoBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithoutSenderInfoBubbleCell.m index 28d317cf4..41aec08ad 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithoutSenderInfoBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomOutgoingEncryptedAttachmentWithoutSenderInfoBubbleCell.m @@ -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 \ No newline at end of file +@end diff --git a/Riot/Modules/Room/Views/BubbleCells/RoomSelectedStickerBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/RoomSelectedStickerBubbleCell.m index f63b5180c..b1e6d9477 100644 --- a/Riot/Modules/Room/Views/BubbleCells/RoomSelectedStickerBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/RoomSelectedStickerBubbleCell.m @@ -163,7 +163,7 @@ { // Set the right device info icon self.encryptionStatusView.hidden = NO; - self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession]; + self.encryptionStatusView.image = [RoomEncryptedDataBubbleCell encryptionIconForBubbleComponent:component]; } else {