From b68002cbb445e183616e77eceb3b9f8ff6db950e Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 26 Jan 2023 09:38:12 +0200 Subject: [PATCH] Drop the entire sliding sync observer and updating rooms by identifiers now that we can request to be sent item updates --- .../xcshareddata/swiftpm/Package.resolved | 4 +- .../Sources/Services/Client/ClientProxy.swift | 24 ++------- .../Client/SlidingSyncViewProxy.swift | 2 +- .../RoomSummary/MockRoomSummaryProvider.swift | 2 - .../RoomSummary/RoomSummaryProvider.swift | 49 ------------------- .../RoomSummaryProviderProtocol.swift | 7 +-- 6 files changed, 7 insertions(+), 81 deletions(-) diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index b14bec7f2..d371686e3 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-rust-components-swift", "state" : { - "revision" : "a119a8f16bbe3adc34cfdf2e092886d44e01705a", - "version" : "1.0.32-alpha" + "revision" : "2d702d0d52805e4f81924507b39ad81c8a74a63f", + "version" : "1.0.33-alpha" } }, { diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 2866b81a7..702bc49ce 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -19,7 +19,7 @@ import Foundation import MatrixRustSDK import UIKit -private class WeakClientProxyWrapper: ClientDelegate, SlidingSyncObserver { +private class WeakClientProxyWrapper: ClientDelegate { private weak var clientProxy: ClientProxy? init(clientProxy: ClientProxy) { @@ -39,17 +39,6 @@ private class WeakClientProxyWrapper: ClientDelegate, SlidingSyncObserver { MXLog.info("Did update restoration token") clientProxy?.didUpdateRestoreToken() } - - // MARK: - SlidingSyncDelegate - - func didReceiveSyncUpdate(summary: UpdateSummary) { - if summary.views.isEmpty, summary.rooms.isEmpty { - return - } - - MXLog.info("Received sliding sync update") - clientProxy?.didReceiveSlidingSyncUpdate(summary: summary) - } } class ClientProxy: ClientProxyProtocol { @@ -269,6 +258,7 @@ class ClientProxy: ClientProxyProtocol { .name(name: "CurrentlyVisibleRooms") .syncMode(mode: .selective) .addRange(from: 0, to: 20) + .sendUpdatesForItems(enable: true) .build() let slidingSync = try slidingSyncBuilder @@ -277,8 +267,6 @@ class ClientProxy: ClientProxyProtocol { .coldCache(name: "ElementX") .build() - slidingSync.setObserver(observer: WeakClientProxyWrapper(clientProxy: self)) - self.slidingSync = slidingSync buildAndConfigureVisibleRoomsSlidingSyncView(slidingSync: slidingSync, visibleRoomsView: visibleRoomsView) @@ -324,6 +312,7 @@ class ClientProxy: ClientProxyProtocol { .syncMode(mode: .growingFullSync) .batchSize(batchSize: 100) .roomLimit(limit: 500) + .sendUpdatesForItems(enable: true) .build() let allRoomsViewProxy = SlidingSyncViewProxy(slidingSync: slidingSync, slidingSyncView: allRoomsView) @@ -382,13 +371,6 @@ class ClientProxy: ClientProxyProtocol { callbacks.send(.updatedRestoreToken) } - fileprivate func didReceiveSlidingSyncUpdate(summary: UpdateSummary) { - visibleRoomsSummaryProvider?.updateRoomsWithIdentifiers(summary.rooms) - allRoomsSummaryProvider?.updateRoomsWithIdentifiers(summary.rooms) - - callbacks.send(.receivedSyncUpdate) - } - /// Convenience method to get the json string of an Encodable private func jsonString(from dictionary: [AnyHashable: Any]?) -> String? { guard let dictionary, diff --git a/ElementX/Sources/Services/Client/SlidingSyncViewProxy.swift b/ElementX/Sources/Services/Client/SlidingSyncViewProxy.swift index 21c437c5a..cbf75dabd 100644 --- a/ElementX/Sources/Services/Client/SlidingSyncViewProxy.swift +++ b/ElementX/Sources/Services/Client/SlidingSyncViewProxy.swift @@ -31,7 +31,7 @@ private class SlidingSyncViewObserver: SlidingSyncViewRoomListObserver, SlidingS // MARK: - SlidingSyncViewRoomListObserver func didReceiveUpdate(diff: SlidingSyncViewRoomsListDiff) { - MXLog.info("Received room diff") + MXLog.verbose("Received room diff") roomListDiffPublisher.send(diff) } diff --git a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift index d0f94d062..bb9fc6d5f 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift @@ -44,8 +44,6 @@ class MockRoomSummaryProvider: RoomSummaryProviderProtocol { } } - func updateRoomsWithIdentifiers(_ identifiers: [String]) { } - func updateVisibleRange(_ range: Range) { } // MARK: - Private diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 7a8a6bdba..4770a9d88 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -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) { 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.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") diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift index f622f7077..9ecb5d7d3 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift @@ -49,11 +49,6 @@ protocol RoomSummaryProviderProtocol { /// Publishes the total number of rooms var countPublisher: CurrentValueSubject { 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) }