Expose sliding sync proxy URL on the server selection screen; make app more resilient to slidinc sync configuration errors, remove fatal errors

This commit is contained in:
Stefan Ceriu
2022-11-17 09:33:39 +02:00
committed by Stefan Ceriu
parent 2fd0491a18
commit 276daf0355
10 changed files with 88 additions and 55 deletions
@@ -55,22 +55,16 @@ class ClientProxy: ClientProxyProtocol {
private let clientQueue: DispatchQueue
private var slidingSyncObserverToken: StoppableSpawn?
private var slidingSync: SlidingSync!
private var slidingSync: SlidingSync?
var roomSummaryProviderInternal: RoomSummaryProviderProtocol!
var roomSummaryProvider: RoomSummaryProviderProtocol {
guard let roomSummaryProviderInternal else {
fatalError("There is an issue with ClientProxy object initialization")
}
return roomSummaryProviderInternal
}
var roomSummaryProvider: RoomSummaryProviderProtocol?
deinit {
// These need to be inlined instead of using stopSync()
// as we can't call async methods safely from deinit
client.setDelegate(delegate: nil)
slidingSyncObserverToken?.cancel()
slidingSync.setObserver(observer: nil)
slidingSync?.setObserver(observer: nil)
}
let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
@@ -84,7 +78,7 @@ class ClientProxy: ClientProxyProtocol {
await Task.dispatch(on: clientQueue) {
do {
let slidingSyncBuilder = try client.slidingSync().homeserver(url: BuildSettings.slidingSyncProxyBaseURL.absoluteString)
let slidingSyncBuilder = try client.slidingSync().homeserver(url: ElementSettings.shared.slidingSyncProxyBaseURLString)
let slidingSyncView = try SlidingSyncViewBuilder()
.timelineLimit(limit: 10)
@@ -94,16 +88,18 @@ class ClientProxy: ClientProxyProtocol {
.syncMode(mode: .fullSync)
.build()
self.slidingSync = try slidingSyncBuilder
let slidingSync = try slidingSyncBuilder
.addView(v: slidingSyncView)
.withCommonExtensions()
.build()
self.roomSummaryProviderInternal = RoomSummaryProvider(slidingSyncController: self.slidingSync,
slidingSyncView: slidingSyncView,
roomMessageFactory: RoomMessageFactory())
self.roomSummaryProvider = RoomSummaryProvider(slidingSyncController: slidingSync,
slidingSyncView: slidingSyncView,
roomMessageFactory: RoomMessageFactory())
self.slidingSync = slidingSync
} catch {
fatalError("Failed configuring sliding sync")
MXLog.error("Failed configuring sliding sync with error: \(error)")
}
}
@@ -150,15 +146,15 @@ class ClientProxy: ClientProxyProtocol {
return
}
slidingSync.setObserver(observer: WeakClientProxyWrapper(clientProxy: self))
slidingSyncObserverToken = slidingSync.sync()
slidingSync?.setObserver(observer: WeakClientProxyWrapper(clientProxy: self))
slidingSyncObserverToken = slidingSync?.sync()
}
func stopSync() {
client.setDelegate(delegate: nil)
slidingSyncObserverToken?.cancel()
slidingSync.setObserver(observer: nil)
slidingSync?.setObserver(observer: nil)
}
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
@@ -252,7 +248,7 @@ class ClientProxy: ClientProxyProtocol {
private func roomTupleForIdentifier(_ identifier: String) -> (SlidingSyncRoom?, Room?) {
do {
let slidingSyncRoom = try slidingSync.getRoom(roomId: identifier)
let slidingSyncRoom = try slidingSync?.getRoom(roomId: identifier)
let fullRoom = slidingSyncRoom?.fullRoom()
return (slidingSyncRoom, fullRoom)
@@ -271,7 +267,7 @@ class ClientProxy: ClientProxyProtocol {
}
fileprivate func didReceiveSlidingSyncUpdate(summary: UpdateSummary) {
roomSummaryProvider.updateRoomsWithIdentifiers(summary.rooms)
roomSummaryProvider?.updateRoomsWithIdentifiers(summary.rooms)
callbacks.send(.receivedSyncUpdate)
}