From 943f33b496a920d4713341614131cf4938c501b5 Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:42:58 +0200 Subject: [PATCH] Await for room sync only for push notification invites (#3307) --- ElementX/Sources/Application/AppCoordinator.swift | 12 +++++++++++- .../Sources/Mocks/Generated/GeneratedMocks.swift | 5 +++++ ElementX/Sources/Services/Client/ClientProxy.swift | 12 +++++++++--- .../Services/Client/ClientProxyProtocol.swift | 2 ++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 7b959bd65..c979c0035 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -32,7 +32,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg private var userSession: UserSessionProtocol? { didSet { userSessionObserver?.cancel() - if userSession != nil { + if let userSession { + userSession.clientProxy.roomsToAwait = storedRoomsToAwait configureElementCallService() configureNotificationManager() observeUserSessionChanges() @@ -57,6 +58,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg private let appRouteURLParser: AppRouteURLParser @Consumable private var storedAppRoute: AppRoute? + private var storedRoomsToAwait: Set = [] init(appDelegate: AppDelegate) { let appHooks = AppHooks() @@ -303,6 +305,14 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg return } + if content.categoryIdentifier == NotificationConstants.Category.invite { + if let userSession { + userSession.clientProxy.roomsToAwait.insert(roomID) + } else { + storedRoomsToAwait.insert(roomID) + } + } + handleAppRoute(.room(roomID: roomID, via: [])) } diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 78eeae919..ba521052f 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -1970,6 +1970,11 @@ class ClientProxyMock: ClientProxyProtocol { var underlyingIgnoredUsersPublisher: CurrentValuePublisher<[String]?, Never>! var pusherNotificationClientIdentifier: String? var roomSummaryProvider: RoomSummaryProviderProtocol? + var roomsToAwait: Set { + get { return underlyingRoomsToAwait } + set(value) { underlyingRoomsToAwait = value } + } + var underlyingRoomsToAwait: Set! var alternateRoomSummaryProvider: RoomSummaryProviderProtocol? var notificationSettings: NotificationSettingsProxyProtocol { get { return underlyingNotificationSettings } diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 731ba02a6..b06c3e0ce 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -112,6 +112,8 @@ class ClientProxy: ClientProxyProtocol { verificationStateSubject.asCurrentValuePublisher() } + var roomsToAwait: Set = [] + private let sendQueueStatusSubject = CurrentValueSubject(false) init(client: ClientProtocol, @@ -431,6 +433,8 @@ class ClientProxy: ClientProxyProtocol { } func roomForIdentifier(_ identifier: String) async -> RoomProxyType? { + let shouldAwait = roomsToAwait.remove(identifier) != nil + // Try fetching the room from the cold cache (if available) first if let room = await buildRoomForIdentifier(identifier) { return room @@ -446,6 +450,10 @@ class ClientProxy: ClientProxyProtocol { _ = await roomSummaryProvider.statePublisher.values.first(where: { $0.isLoaded }) } + if shouldAwait { + await waitForRoomToSync(roomID: identifier) + } + return await buildRoomForIdentifier(identifier) } @@ -836,9 +844,7 @@ class ClientProxy: ClientProxyProtocol { MXLog.error("Failed retrieving room: \(roomID), room list service not set up") return nil } - - await waitForRoomToSync(roomID: roomID) - + do { let roomListItem = try roomListService.room(roomId: roomID) diff --git a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift index 5eca4a140..29a5a856c 100644 --- a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift @@ -114,6 +114,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol { var roomSummaryProvider: RoomSummaryProviderProtocol? { get } + var roomsToAwait: Set { get set } + /// Used for listing rooms that shouldn't be affected by the main `roomSummaryProvider` filtering var alternateRoomSummaryProvider: RoomSummaryProviderProtocol? { get }