From 590655197d0dbe2ea709a8766f2957b1a1a7f2bd Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 29 May 2023 11:21:01 +0300 Subject: [PATCH] Notification deep linking fix (#972) * Fixed unused animated parameter * Wait for lists to load before querying rooms if the cold cache isn't available * Fix a couple of unused result warnings in the ExpiringTaskRunner unit tests --- .../UserSessionFlowCoordinator.swift | 2 +- .../Sources/Services/Client/ClientProxy.swift | 24 ++++++++++++++++++- .../Sources/ExpiringTaskRunnerTests.swift | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift index d74dd3727..0ed72a49a 100644 --- a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift @@ -94,7 +94,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { switch appRoute { case .room, .roomDetails, .roomList: - roomFlowCoordinator.handleAppRoute(appRoute, animated: true) + roomFlowCoordinator.handleAppRoute(appRoute, animated: animated) } } diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 91a4726ac..facb09363 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -242,7 +242,29 @@ class ClientProxy: ClientProxyProtocol { } func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? { - let (slidingSyncRoom, room) = await Task.dispatch(on: clientQueue) { + // Try fetching the room from the cold cache (if available) first + var (slidingSyncRoom, room) = await Task.dispatch(on: clientQueue) { + self.roomTupleForIdentifier(identifier) + } + + if let slidingSyncRoom, let room { + return await RoomProxy(slidingSyncRoom: slidingSyncRoom, + room: room, + backgroundTaskService: backgroundTaskService) + } + + // Else wait for the visible rooms list to go into fully loaded + + guard let visibleRoomsSummaryProvider else { + MXLog.error("Visible rooms summary provider not setup yet") + return nil + } + + if visibleRoomsSummaryProvider.statePublisher.value != .fullyLoaded { + _ = await visibleRoomsSummaryProvider.statePublisher.values.first(where: { $0 == .fullyLoaded }) + } + + (slidingSyncRoom, room) = await Task.dispatch(on: clientQueue) { self.roomTupleForIdentifier(identifier) } diff --git a/UnitTests/Sources/ExpiringTaskRunnerTests.swift b/UnitTests/Sources/ExpiringTaskRunnerTests.swift index b41c5c7d3..e5991989a 100644 --- a/UnitTests/Sources/ExpiringTaskRunnerTests.swift +++ b/UnitTests/Sources/ExpiringTaskRunnerTests.swift @@ -42,7 +42,7 @@ class ExpiringTaskRunnerTests: XCTestCase { } do { - let result = try await runner.run(timeout: .seconds(1)) + _ = try await runner.run(timeout: .seconds(1)) } catch { XCTAssertEqual(error as? ExpiringTaskTestError, ExpiringTaskTestError.failed) } @@ -55,7 +55,7 @@ class ExpiringTaskRunnerTests: XCTestCase { } do { - let result = try await runner.run(timeout: .milliseconds(100)) + _ = try await runner.run(timeout: .milliseconds(100)) } catch { XCTAssertEqual(error as? ExpiringTaskRunnerError, ExpiringTaskRunnerError.timeout) }