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

Threads: added support to read receipts (MSC3771) #6964

Merged
merged 5 commits into from
Nov 4, 2022
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
53 changes: 45 additions & 8 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -2358,18 +2358,46 @@ - (void)didReceiveReceiptEvent:(MXEvent *)receiptEvent roomState:(MXRoomState *)

// Update cell data we have received a read receipt for
NSArray *readEventIds = receiptEvent.readReceiptEventIds;
for (NSString* eventId in readEventIds)
NSArray *readThreadIds = receiptEvent.readReceiptThreadIds;
for (int i = 0 ; i < readEventIds.count ; i++)
{
NSString *eventId = readEventIds[i];
MXKRoomBubbleCellData *cellData = [self cellDataOfEventWithEventId:eventId];
if (cellData)
{
@synchronized(self->bubbles)
if ([readThreadIds[i] isEqualToString:kMXEventUnthreaded])
{
dispatch_group_enter(dispatchGroup);
[self addReadReceiptsForEvent:eventId inCellDatas:self->bubbles startingAtCellData:cellData completion:^{
dispatch_group_leave(dispatchGroup);
// Unthreaded RR must be propagated through all threads.
[self.mxSession.threadingService allThreadsInRoomWithId:self.roomId onlyParticipated:NO completion:^(NSArray<id<MXThreadProtocol>> *threads) {
NSMutableArray *threadIds = [NSMutableArray arrayWithObject:kMXEventTimelineMain];
for (id<MXThreadProtocol> thread in threads)
{
[threadIds addObject:thread.id];
}

for (NSString *threadId in threadIds)
{
@synchronized(self->bubbles)
{
dispatch_group_enter(dispatchGroup);
[self addReadReceiptsForEvent:eventId threadId:threadId inCellDatas:self->bubbles startingAtCellData:cellData completion:^{
dispatch_group_leave(dispatchGroup);
}];
}
}
}];
}
else
{
NSString *threadId = readThreadIds[i];
@synchronized(self->bubbles)
{
dispatch_group_enter(dispatchGroup);
[self addReadReceiptsForEvent:eventId threadId:threadId inCellDatas:self->bubbles startingAtCellData:cellData completion:^{
dispatch_group_leave(dispatchGroup);
}];
}
}
}
}

Expand Down Expand Up @@ -3512,7 +3540,10 @@ - (void)processQueuedEvents:(void (^)(NSUInteger addedHistoryCellNb, NSUInteger
@autoreleasepool
{
dispatch_group_enter(dispatchGroup);
[self addReadReceiptsForEvent:queuedEvent.event.eventId inCellDatas:self->bubblesSnapshot startingAtCellData:self->eventIdToBubbleMap[queuedEvent.event.eventId] completion:^{
[self addReadReceiptsForEvent:queuedEvent.event.eventId
threadId:queuedEvent.event.threadId
inCellDatas:self->bubblesSnapshot
startingAtCellData:self->eventIdToBubbleMap[queuedEvent.event.eventId] completion:^{
dispatch_group_leave(dispatchGroup);
}];
}
Expand Down Expand Up @@ -3667,16 +3698,22 @@ Add the read receipts of an event into the timeline (which is in array of cell d
If the event is not displayed, read receipts will be added to a previous displayed message.

@param eventId the id of the event.
@param threadId the Id of the thread related of the event.
@param cellDatas the working array of cell datas.
@param cellData the original cell data the event belongs to.
@param completion completion block
*/
- (void)addReadReceiptsForEvent:(NSString*)eventId inCellDatas:(NSArray<id<MXKRoomBubbleCellDataStoring>>*)cellDatas startingAtCellData:(id<MXKRoomBubbleCellDataStoring>)cellData completion:(void (^)(void))completion
- (void)addReadReceiptsForEvent:(NSString*)eventId
threadId:(NSString *)threadId
inCellDatas:(NSArray<id<MXKRoomBubbleCellDataStoring>>*)cellDatas
startingAtCellData:(id<MXKRoomBubbleCellDataStoring>)cellData
completion:(void (^)(void))completion
{
if (self.showBubbleReceipts)
{
if (self.room)
{
[self.room getEventReceipts:eventId sorted:YES completion:^(NSArray<MXReceiptData *> * _Nonnull readReceipts) {
[self.room getEventReceipts:eventId threadId:threadId sorted:YES completion:^(NSArray<MXReceiptData *> * _Nonnull readReceipts) {
if (readReceipts.count)
{
NSInteger cellDataIndex = [cellDatas indexOfObject:cellData];
Expand Down
20 changes: 2 additions & 18 deletions Riot/Modules/Room/DataSources/ThreadDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class ThreadDataSource: RoomDataSource {

public override func finalizeInitialization() {
super.finalizeInitialization()
showReadMarker = false
showBubbleReceipts = false
showReadMarker = true
gileluard marked this conversation as resolved.
Show resolved Hide resolved
showBubbleReceipts = true
showTypingRow = false

NotificationCenter.default.addObserver(self,
Expand All @@ -42,22 +42,6 @@ public class ThreadDataSource: RoomDataSource {
object: nil)
}

public override var showReadMarker: Bool {
get {
return false
} set {
_ = newValue
}
}

public override var showBubbleReceipts: Bool {
get {
return false
} set {
_ = newValue
}
}

public override class func load(withRoomId roomId: String!,
initialEventId: String!,
threadId: String!,
Expand Down
7 changes: 6 additions & 1 deletion Riot/Modules/Room/MXKRoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ - (void)viewDidAppear:(BOOL)animated

// Mark all messages as read when the room is displayed
[self.roomDataSource.room.summary markAllAsReadLocally];

[self updateCurrentEventIdAtTableBottom:YES];
}

- (void)viewWillDisappear:(BOOL)animated
Expand Down Expand Up @@ -2497,7 +2499,10 @@ - (void)updateCurrentEventIdAtTableBottom:(BOOL)acknowledge
updateReadMarker = (currentReadMarkerEvent && (currentReadMarkerEvent.originServerTs <= component.event.originServerTs));
}

[roomDataSource.room acknowledgeEvent:component.event andUpdateReadMarker:updateReadMarker];
if (self.navigationController.viewControllers.lastObject == self)
{
[roomDataSource.room acknowledgeEvent:component.event andUpdateReadMarker:updateReadMarker];
}
}
break;
}
Expand Down
4 changes: 0 additions & 4 deletions Riot/Modules/Threads/ThreadsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ final class ThreadsCoordinator: NSObject, ThreadsCoordinatorProtocol {
// Detect when view controller has been dismissed by gesture when presented modally (not in full screen).
self.navigationRouter.toPresentable().presentationController?.delegate = self

guard parameters.threadId == nil else {
return
}

if self.navigationRouter.modules.isEmpty == false {
self.navigationRouter.push(rootCoordinator, animated: true, popCompletion: { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
Expand Down
2 changes: 1 addition & 1 deletion RiotNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ class NotificationService: UNNotificationServiceExtension {
return
}

mxRestClient.sendReadReceipt(toRoom: roomId, forEvent: eventId) { response in
mxRestClient.sendReadReceipt(toRoom: roomId, forEvent: eventId, threadId: event.threadId) { response in
if response.isSuccess {
MXLog.debug("[NotificationService] sendReadReceipt: Read receipt send successfully.")
} else if let error = response.error {
Expand Down
1 change: 1 addition & 0 deletions changelog.d/6663.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Threads: added support to read receipts (MSC3771)