From a8fd68a3cb4ac4ff853598360c93f347ff0ef81b Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:43:01 +0100 Subject: [PATCH] Sending all RR when the app is active client side. (#2443) --- .../RoomScreen/RoomScreenViewModel.swift | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 3d05fcd2b..aeebb44d1 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -392,50 +392,21 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol } } - /// The ID of the newest item in the room that the user has seen. - /// This includes both event based items and virtual items. - private var lastReadItemID: TimelineItemIdentifier? private func sendReadReceiptIfNeeded(for lastVisibleItemID: TimelineItemIdentifier) async { guard application.applicationState == .active else { return } - guard lastReadItemID != lastVisibleItemID, - let eventItemID = eventBasedItem(nearest: lastVisibleItemID) else { - return - } - - // Make sure the item is newer than the item that was last marked as read. - if let lastReadItemIndex = state.timelineViewState.timelineIDs.firstIndex(of: lastReadItemID?.timelineID ?? ""), - let lastVisibleItemIndex = state.timelineViewState.timelineIDs.firstIndex(of: eventItemID.timelineID), - lastReadItemIndex > lastVisibleItemIndex { - return - } - - // Update the last read item ID to avoid attempting duplicate requests. - lastReadItemID = lastVisibleItemID - // Clear any notifications from notification center. if lastVisibleItemID.timelineID == state.timelineViewState.timelineIDs.last { notificationCenter.post(name: .roomMarkedAsRead, object: roomProxy.id) } - switch await timelineController.sendReadReceipt(for: eventItemID) { + switch await timelineController.sendReadReceipt(for: lastVisibleItemID) { case .success: break case let .failure(error): MXLog.error("[TimelineViewController] Failed to send read receipt: \(error)") } } - - /// Returns the first item ID that contains an `eventID` starting from the supplied ID, working backwards through the timeline. - private func eventBasedItem(nearest itemID: TimelineItemIdentifier) -> TimelineItemIdentifier? { - guard itemID.eventID == nil else { return itemID } - - let timelineIDs = state.timelineViewState.itemViewStates.map(\.identifier) - guard let index = timelineIDs.firstIndex(of: itemID) else { return nil } - - let nearestItemID = timelineIDs[..