Fixes #2842, fixes #2841 - Adopt new message sending queue API

- automatically retry failed requests as soon as the network is availble again
- remove manual retry options
This commit is contained in:
Stefan Ceriu
2024-05-28 10:17:13 +03:00
committed by Stefan Ceriu
parent 53fc5df55b
commit 6c1647b851
28 changed files with 827 additions and 606 deletions
@@ -45,6 +45,9 @@ class ClientProxy: ClientProxyProtocol {
// periphery:ignore - required for instance retention in the rust codebase
private var verificationStateListenerTaskHandle: TaskHandle?
// periphery:ignore - required for instance retention in the rust codebase
private var sendingQueueListenerTaskHandle: TaskHandle?
private var delegateHandle: TaskHandle?
// These following summary providers both operate on the same allRooms() list but
@@ -161,6 +164,17 @@ class ClientProxy: ClientProxyProtocol {
verificationStateListenerTaskHandle = client.encryption().verificationStateListener(listener: VerificationStateListenerProxy { [weak self] verificationState in
self?.updateVerificationState(verificationState)
})
sendingQueueListenerTaskHandle = client.subscribeToSendingQueueStatus(listener: SendingQueueStatusListenerProxy { [weak self] enabled in
guard let self else { return }
MXLog.error("Sending queue status changed to enabled: \(enabled)")
if enabled == false,
networkMonitor.reachabilityPublisher.value == .reachable {
setSendingQueueEnabled(true)
}
})
}
private func updateVerificationState(_ verificationState: VerificationState) {
@@ -578,6 +592,11 @@ class ClientProxy: ClientProxyProtocol {
}
}
func setSendingQueueEnabled(_ enabled: Bool) {
MXLog.info("Setting sending queue to enabled: \(enabled)")
client.enableSendingQueue(enable: enabled)
}
// MARK: Ignored users
func ignoreUser(_ userID: String) async -> Result<Void, ClientProxyError> {
@@ -784,7 +803,7 @@ class ClientProxy: ClientProxyProtocol {
if roomListItem?.isTimelineInitialized() == false {
try await roomListItem?.initTimeline(eventTypeFilter: eventFilters, internalIdPrefix: nil)
}
let fullRoom = try await roomListItem?.fullRoom()
let fullRoom = try roomListItem?.fullRoom()
return (roomListItem, fullRoom)
} catch {
@@ -920,6 +939,18 @@ private class IgnoredUsersListenerProxy: IgnoredUsersListener {
}
}
private class SendingQueueStatusListenerProxy: SendingQueueStatusListener {
private let onUpdateClosure: (Bool) -> Void
init(onUpdateClosure: @escaping (Bool) -> Void) {
self.onUpdateClosure = onUpdateClosure
}
func onUpdate(newValue: Bool) {
onUpdateClosure(newValue)
}
}
private extension RoomPreviewDetails {
init(_ roomPreview: RoomPreview) {
self = RoomPreviewDetails(roomID: roomPreview.roomId,