diff --git a/CHANGES.rst b/CHANGES.rst index a923de8aa..9761acd5a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,7 @@ Improvements: * Context menu polish (#2466). * Message Editing: Annotate edited messages in timeline (#2400). * Message Editing: Editing in the timeline (#2404). + * Read receipts: They are now counted at the MatrixKit level. Bug fix: * Device Verification: Fix user display name and device id colors in dark theme diff --git a/Riot/Modules/Room/CellData/RoomBubbleCellData.m b/Riot/Modules/Room/CellData/RoomBubbleCellData.m index 0637c96e1..43eb3903d 100644 --- a/Riot/Modules/Room/CellData/RoomBubbleCellData.m +++ b/Riot/Modules/Room/CellData/RoomBubbleCellData.m @@ -73,10 +73,6 @@ static NSAttributedString *timestampVerticalWhitespace = nil; // Increase maximum number of components self.maxComponentCount = 20; - - // Initialize read receipts - self.readReceipts = [NSMutableDictionary dictionary]; - self.readReceipts[event.eventId] = [roomDataSource.room getEventReceipts:event.eventId sorted:YES]; // Reset attributedTextMessage to force reset MXKRoomCellData parameters self.attributedTextMessage = nil; @@ -630,9 +626,6 @@ static NSAttributedString *timestampVerticalWhitespace = nil; return NO; } - // Update read receipts for this bubble - self.readReceipts[event.eventId] = [roomDataSource.room getEventReceipts:event.eventId sorted:YES]; - return [super addEvent:event andRoomState:roomState]; } diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index af4e4a99a..3bcdf9b5b 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -120,106 +120,6 @@ [super destroy]; } -- (void)didReceiveReceiptEvent:(MXEvent *)receiptEvent roomState:(MXRoomState *)roomState -{ - // Do the processing on the same processing queue as MXKRoomDataSource - dispatch_async(MXKRoomDataSource.processingQueue, ^{ - - // Remove the previous displayed read receipt for each user who sent a - // new read receipt. - // To implement it, we need to find the sender id of each new read receipt - // among the read receipts array of all events in all bubbles. - NSArray *readReceiptSenders = receiptEvent.readReceiptSenders; - - @synchronized(bubbles) - { - for (RoomBubbleCellData *cellData in bubbles) - { - NSMutableDictionary *> *updatedCellDataReadReceipts = [NSMutableDictionary dictionary]; - - for (NSString *eventId in cellData.readReceipts) - { - for (MXReceiptData *receiptData in cellData.readReceipts[eventId]) - { - for (NSString *senderId in readReceiptSenders) - { - if ([receiptData.userId isEqualToString:senderId]) - { - if (!updatedCellDataReadReceipts[eventId]) - { - updatedCellDataReadReceipts[eventId] = cellData.readReceipts[eventId]; - } - - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userId!=%@", receiptData.userId]; - updatedCellDataReadReceipts[eventId] = [updatedCellDataReadReceipts[eventId] filteredArrayUsingPredicate:predicate]; - break; - } - } - - } - } - - // Flush found changed to the cell data - for (NSString *eventId in updatedCellDataReadReceipts) - { - if (updatedCellDataReadReceipts[eventId].count) - { - cellData.readReceipts[eventId] = updatedCellDataReadReceipts[eventId]; - } - else - { - cellData.readReceipts[eventId] = nil; - } - - [cellData setNeedsUpdateAdditionalContentHeight]; - } - } - } - - // Update cell data we have received a read receipt for - NSArray *readEventIds = receiptEvent.readReceiptEventIds; - for (NSString* eventId in readEventIds) - { - RoomBubbleCellData *cellData = [self cellDataOfEventWithEventId:eventId]; - if (cellData) - { - @synchronized(bubbles) - { - if (!cellData.hasNoDisplay) - { - cellData.readReceipts[eventId] = [self.room getEventReceipts:eventId sorted:YES]; - } - else - { - // Ignore the read receipts on the events without an actual display. - cellData.readReceipts[eventId] = nil; - } - - [cellData setNeedsUpdateAdditionalContentHeight]; - } - } - } - - dispatch_async(dispatch_get_main_queue(), ^{ - // TODO: Be smarter and update only updated cells - [super didReceiveReceiptEvent:receiptEvent roomState:roomState]; - }); - }); -} - -- (void)updateCellDataReactions:(id)cellData forEventId:(NSString*)eventId -{ - [super updateCellDataReactions:cellData forEventId:eventId]; - - RoomBubbleCellData *roomBubbleCellData; - - if ([cellData isKindOfClass:[RoomBubbleCellData class]]) - { - roomBubbleCellData = (RoomBubbleCellData*)cellData; - [roomBubbleCellData setNeedsUpdateAdditionalContentHeight]; - } -} - #pragma mark - - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section