mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Sending all RR when the app is active client side. (#2443)
This commit is contained in:
@@ -392,33 +392,15 @@ 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 {
|
private func sendReadReceiptIfNeeded(for lastVisibleItemID: TimelineItemIdentifier) async {
|
||||||
guard application.applicationState == .active else { return }
|
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.
|
// Clear any notifications from notification center.
|
||||||
if lastVisibleItemID.timelineID == state.timelineViewState.timelineIDs.last {
|
if lastVisibleItemID.timelineID == state.timelineViewState.timelineIDs.last {
|
||||||
notificationCenter.post(name: .roomMarkedAsRead, object: roomProxy.id)
|
notificationCenter.post(name: .roomMarkedAsRead, object: roomProxy.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch await timelineController.sendReadReceipt(for: eventItemID) {
|
switch await timelineController.sendReadReceipt(for: lastVisibleItemID) {
|
||||||
case .success:
|
case .success:
|
||||||
break
|
break
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
@@ -426,17 +408,6 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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[..<index].last(where: { $0.eventID != nil })
|
|
||||||
return nearestItemID
|
|
||||||
}
|
|
||||||
|
|
||||||
private func handleItemTapped(with itemID: TimelineItemIdentifier) async {
|
private func handleItemTapped(with itemID: TimelineItemIdentifier) async {
|
||||||
state.showLoading = true
|
state.showLoading = true
|
||||||
let action = await roomScreenInteractionHandler.processItemTap(itemID)
|
let action = await roomScreenInteractionHandler.processItemTap(itemID)
|
||||||
|
|||||||
Reference in New Issue
Block a user