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
@@ -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"
}
},
{
@@ -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,
@@ -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)
}
@@ -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>)
}