From d996c69a6659e959a49bf451a860644adb5889dd Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 5 Apr 2024 09:16:31 +0300 Subject: [PATCH] Small recently visited room tweaks following PR review --- .../FlowCoordinators/RoomFlowCoordinator.swift | 6 +++--- .../InviteUsersScreenCoordinator.swift | 11 +++++------ .../InviteUsersScreenViewModel.swift | 9 ++++----- .../InviteUsersScreen/View/InviteUsersScreen.swift | 6 +++--- .../StartChatScreen/StartChatScreenCoordinator.swift | 6 +++--- ElementX/Sources/Services/Client/ClientProxy.swift | 10 ++++++---- .../Sources/Services/Users/UserProfileProxy.swift | 2 +- UnitTests/Sources/InviteUsersViewModelTests.swift | 6 +++--- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index e9c0cbfdf..918604776 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -1010,11 +1010,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { let stackCoordinator = NavigationStackCoordinator() let inviteParameters = InviteUsersScreenCoordinatorParameters(clientProxy: userSession.clientProxy, + selectedUsers: .init(selectedUsersSubject), + roomType: .room(roomProxy: roomProxy), mediaProvider: userSession.mediaProvider, userDiscoveryService: UserDiscoveryService(clientProxy: userSession.clientProxy), - userIndicatorController: userIndicatorController, - selectedUsers: .init(selectedUsersSubject), - roomType: .room(roomProxy: roomProxy)) + userIndicatorController: userIndicatorController) let coordinator = InviteUsersScreenCoordinator(parameters: inviteParameters) stackCoordinator.setRootCoordinator(coordinator) diff --git a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenCoordinator.swift b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenCoordinator.swift index c0cb08d8c..fd36828e8 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenCoordinator.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenCoordinator.swift @@ -19,12 +19,11 @@ import SwiftUI struct InviteUsersScreenCoordinatorParameters { let clientProxy: ClientProxyProtocol + let selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never> + let roomType: InviteUsersScreenRoomType let mediaProvider: MediaProviderProtocol let userDiscoveryService: UserDiscoveryServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol - - let selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never> - let roomType: InviteUsersScreenRoomType } enum InviteUsersScreenCoordinatorAction { @@ -45,11 +44,11 @@ final class InviteUsersScreenCoordinator: CoordinatorProtocol { init(parameters: InviteUsersScreenCoordinatorParameters) { viewModel = InviteUsersScreenViewModel(clientProxy: parameters.clientProxy, + selectedUsers: parameters.selectedUsers, + roomType: parameters.roomType, mediaProvider: parameters.mediaProvider, userDiscoveryService: parameters.userDiscoveryService, - userIndicatorController: parameters.userIndicatorController, - selectedUsers: parameters.selectedUsers, - roomType: parameters.roomType) + userIndicatorController: parameters.userIndicatorController) } func start() { diff --git a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift index 07793cab1..54fe30339 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift @@ -34,17 +34,16 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr } init(clientProxy: ClientProxyProtocol, + selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>, + roomType: InviteUsersScreenRoomType, mediaProvider: MediaProviderProtocol, userDiscoveryService: UserDiscoveryServiceProtocol, - userIndicatorController: UserIndicatorControllerProtocol, - selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>, - roomType: InviteUsersScreenRoomType) { + userIndicatorController: UserIndicatorControllerProtocol) { self.clientProxy = clientProxy + self.roomType = roomType self.userDiscoveryService = userDiscoveryService self.userIndicatorController = userIndicatorController - self.roomType = roomType - super.init(initialViewState: InviteUsersScreenViewState(selectedUsers: selectedUsers.value, isCreatingRoom: roomType.isCreatingRoom), imageProvider: mediaProvider) setupSubscriptions(selectedUsers: selectedUsers) diff --git a/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift b/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift index 83b144e54..57d24af1f 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift @@ -161,11 +161,11 @@ struct InviteUsersScreen_Previews: PreviewProvider, TestablePreview { let userDiscoveryService = UserDiscoveryServiceMock() userDiscoveryService.searchProfilesWithReturnValue = .success([.mockAlice]) return InviteUsersScreenViewModel(clientProxy: ClientProxyMock(.init()), + selectedUsers: .init([]), + roomType: .draft, mediaProvider: MockMediaProvider(), userDiscoveryService: userDiscoveryService, - userIndicatorController: UserIndicatorControllerMock(), - selectedUsers: .init([]), - roomType: .draft) + userIndicatorController: UserIndicatorControllerMock()) }() static var previews: some View { diff --git a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift index c353dd20c..df1a79a7d 100644 --- a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift +++ b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift @@ -85,11 +85,11 @@ final class StartChatScreenCoordinator: CoordinatorProtocol { private func presentInviteUsersScreen() { let inviteParameters = InviteUsersScreenCoordinatorParameters(clientProxy: parameters.userSession.clientProxy, + selectedUsers: selectedUsersPublisher, + roomType: .draft, mediaProvider: parameters.userSession.mediaProvider, userDiscoveryService: parameters.userDiscoveryService, - userIndicatorController: parameters.userIndicatorController, - selectedUsers: selectedUsersPublisher, - roomType: .draft) + userIndicatorController: parameters.userIndicatorController) let coordinator = InviteUsersScreenCoordinator(parameters: inviteParameters) coordinator.actions.sink { [weak self] action in guard let self else { return } diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 7d1a03318..57975876f 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -16,8 +16,10 @@ import Combine import CryptoKit +import Foundation +import OrderedCollections + import MatrixRustSDK -import SwiftUI class ClientProxy: ClientProxyProtocol { private let client: ClientProtocol @@ -625,7 +627,7 @@ class ClientProxy: ClientProxyProtocol { return [] } - var users = [UserProfileProxy]() + var users: OrderedSet = [] for roomID in roomIdentifiers { guard let room = await roomForIdentifier(roomID), @@ -639,12 +641,12 @@ class ClientProxy: ClientProxyProtocol { // Return early to avoid unnecessary work if users.count >= maxResultsToReturn { - return users + return users.elements } } } - return users + return users.elements } // MARK: - Private diff --git a/ElementX/Sources/Services/Users/UserProfileProxy.swift b/ElementX/Sources/Services/Users/UserProfileProxy.swift index fde68335c..9b4167dc8 100644 --- a/ElementX/Sources/Services/Users/UserProfileProxy.swift +++ b/ElementX/Sources/Services/Users/UserProfileProxy.swift @@ -17,7 +17,7 @@ import Foundation import MatrixRustSDK -struct UserProfileProxy: Equatable { +struct UserProfileProxy: Equatable, Hashable { let userID: String let displayName: String? let avatarURL: URL? diff --git a/UnitTests/Sources/InviteUsersViewModelTests.swift b/UnitTests/Sources/InviteUsersViewModelTests.swift index eb65431cc..eb7b8ca1c 100644 --- a/UnitTests/Sources/InviteUsersViewModelTests.swift +++ b/UnitTests/Sources/InviteUsersViewModelTests.swift @@ -99,11 +99,11 @@ class InviteUsersScreenViewModelTests: XCTestCase { userDiscoveryService.searchProfilesWithReturnValue = .success([]) usersSubject.send([]) let viewModel = InviteUsersScreenViewModel(clientProxy: ClientProxyMock(.init()), + selectedUsers: usersSubject.asCurrentValuePublisher(), + roomType: roomType, mediaProvider: MockMediaProvider(), userDiscoveryService: userDiscoveryService, - userIndicatorController: UserIndicatorControllerMock(), - selectedUsers: usersSubject.asCurrentValuePublisher(), - roomType: roomType) + userIndicatorController: UserIndicatorControllerMock()) viewModel.state.usersSection = .init(type: .suggestions, users: [.mockAlice, .mockBob, .mockCharlie]) self.viewModel = viewModel