Drop the entire sliding sync observer and updating rooms by identifiers now that we can request to be sent item updates

This commit is contained in:
Stefan Ceriu
2023-01-26 09:38:12 +02:00
committed by Stefan Ceriu
parent bd4c0b72cb
commit b68002cbb4
6 changed files with 7 additions and 81 deletions
@@ -44,8 +44,6 @@ class MockRoomSummaryProvider: RoomSummaryProviderProtocol {
}
}
func updateRoomsWithIdentifiers(_ identifiers: [String]) { }
func updateVisibleRange(_ range: Range<Int>) { }
// MARK: - Private
@@ -61,61 +61,12 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
.store(in: &cancellables)
}
func updateRoomsWithIdentifiers(_ identifiers: [String]) {
serialDispatchQueue.async { [weak self] in
guard let self else { return }
self.updateRoomsForIdentifiers(identifiers)
}
}
func updateVisibleRange(_ range: Range<Int>) {
slidingSyncViewProxy.updateVisibleRange(range)
}
// MARK: - Private
/// Invoked from `updateRoomsWithIdentifiers` on the same dispatch queue as `updateRoomsWithDiffs`
private func updateRoomsForIdentifiers(_ identifiers: [String]) {
guard !identifiers.isEmpty else {
return
}
MXLog.info("Updating \(identifiers.count) rooms")
guard statePublisher.value == .live else {
MXLog.warning("Sliding sync not live yet, ignoring update.")
return
}
var changes = [CollectionDifference<RoomSummary>.Change]()
for identifier in identifiers {
guard let index = rooms.firstIndex(where: { $0.id == identifier }),
let roomListEntry = slidingSyncViewProxy.currentRoomsList().first(where: { $0.id == identifier }) else {
continue
}
let oldRoom = rooms[index]
let newRoom = buildRoomSummaryForIdentifier(identifier, invalidated: roomListEntry.isInvalidated)
changes.append(.remove(offset: index, element: oldRoom, associatedWith: nil))
changes.append(.insert(offset: index, element: newRoom, associatedWith: nil))
}
guard let diff = CollectionDifference(changes) else {
MXLog.error("Failed creating diff from changes: \(changes)")
return
}
guard let newSummaries = rooms.applying(diff) else {
MXLog.error("Failed applying diff: \(diff)")
return
}
rooms = newSummaries
MXLog.verbose("Finished updating \(identifiers.count) rooms")
}
fileprivate func updateRoomsWithDiffs(_ diffs: [SlidingSyncViewRoomsListDiff]) {
MXLog.info("Received \(diffs.count) diffs")
@@ -49,11 +49,6 @@ protocol RoomSummaryProviderProtocol {
/// Publishes the total number of rooms
var countPublisher: CurrentValueSubject<UInt, Never> { get }
/// Invoked by the sliding sync controller whenever certain rooms have updated
/// without necessarily changing their position in the list
/// - Parameter identifiers: the identifiers for the rooms that have changed
func updateRoomsWithIdentifiers(_ identifiers: [String])
func updateVisibleRange(_ range: Range<Int>)
}