Account URL is now fetched async (#2769)

This commit is contained in:
Mauro 2024-04-30 19:08:32 +02:00 committed by GitHub
parent f688d2eda4
commit 18dc9cd20f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 47 additions and 70 deletions

View File

@ -7332,7 +7332,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
requirement = { requirement = {
kind = exactVersion; kind = exactVersion;
version = 1.1.62; version = 1.1.63;
}; };
}; };
821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = { 821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = {

View File

@ -139,8 +139,8 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift", "location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : { "state" : {
"revision" : "c060a2a24f3cfa3cff3f6075bdc1e88abea72553", "revision" : "3d116223646fc7310b977e5116f96b834a9f57f6",
"version" : "1.1.62" "version" : "1.1.63"
} }
}, },
{ {

View File

@ -113,8 +113,8 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {
presentSecureBackupScreen(animated: true) presentSecureBackupScreen(animated: true)
case .userDetails: case .userDetails:
presentUserDetailsEditScreen() presentUserDetailsEditScreen()
case .accountProfile: case let .manageAccount(url):
presentAccountProfileURL() presentAccountManagementURL(url)
case .analytics: case .analytics:
presentAnalyticsScreen() presentAnalyticsScreen()
case .appLock: case .appLock:
@ -130,8 +130,6 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {
presentLegalInformationScreen() presentLegalInformationScreen()
case .blockedUsers: case .blockedUsers:
presentBlockedUsersScreen() presentBlockedUsersScreen()
case .accountSessions:
presentAccountSessionsListURL()
case .notifications: case .notifications:
presentNotificationSettings() presentNotificationSettings()
case .advancedSettings: case .advancedSettings:
@ -243,22 +241,6 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {
// MARK: OIDC Account Management // MARK: OIDC Account Management
private func presentAccountProfileURL() {
guard let url = parameters.userSession.clientProxy.accountURL(action: .profile) else {
MXLog.error("Account URL is missing.")
return
}
presentAccountManagementURL(url)
}
private func presentAccountSessionsListURL() {
guard let url = parameters.userSession.clientProxy.accountURL(action: .sessionsList) else {
MXLog.error("Account URL is missing.")
return
}
presentAccountManagementURL(url)
}
private var accountSettingsPresenter: OIDCAccountSettingsPresenter? private var accountSettingsPresenter: OIDCAccountSettingsPresenter?
private func presentAccountManagementURL(_ url: URL) { private func presentAccountManagementURL(_ url: URL) {
// Note to anyone in the future if you come back here to make this open in Safari instead of a WAS. // Note to anyone in the future if you come back here to make this open in Safari instead of a WAS.

View File

@ -2104,14 +2104,14 @@ class ClientProxyMock: ClientProxyProtocol {
} }
} }
} }
var accountURLActionClosure: ((AccountManagementAction) -> URL?)? var accountURLActionClosure: ((AccountManagementAction) async -> URL?)?
func accountURL(action: AccountManagementAction) -> URL? { func accountURL(action: AccountManagementAction) async -> URL? {
accountURLActionCallsCount += 1 accountURLActionCallsCount += 1
accountURLActionReceivedAction = action accountURLActionReceivedAction = action
accountURLActionReceivedInvocations.append(action) accountURLActionReceivedInvocations.append(action)
if let accountURLActionClosure = accountURLActionClosure { if let accountURLActionClosure = accountURLActionClosure {
return accountURLActionClosure(action) return await accountURLActionClosure(action)
} else { } else {
return accountURLActionReturnValue return accountURLActionReturnValue
} }

View File

@ -135,9 +135,9 @@ class SDKClientMock: SDKClientProtocol {
} }
} }
} }
public var accountUrlActionClosure: ((AccountManagementAction?) throws -> String?)? public var accountUrlActionClosure: ((AccountManagementAction?) async throws -> String?)?
public func accountUrl(action: AccountManagementAction?) throws -> String? { public func accountUrl(action: AccountManagementAction?) async throws -> String? {
if let error = accountUrlActionThrowableError { if let error = accountUrlActionThrowableError {
throw error throw error
} }
@ -145,7 +145,7 @@ class SDKClientMock: SDKClientProtocol {
accountUrlActionReceivedAction = action accountUrlActionReceivedAction = action
accountUrlActionReceivedInvocations.append(action) accountUrlActionReceivedInvocations.append(action)
if let accountUrlActionClosure = accountUrlActionClosure { if let accountUrlActionClosure = accountUrlActionClosure {
return try accountUrlActionClosure(action) return try await accountUrlActionClosure(action)
} else { } else {
return accountUrlActionReturnValue return accountUrlActionReturnValue
} }

View File

@ -27,13 +27,12 @@ enum SettingsScreenCoordinatorAction {
case logout case logout
case secureBackup case secureBackup
case userDetails case userDetails
case accountProfile
case analytics case analytics
case appLock case appLock
case bugReport case bugReport
case about case about
case blockedUsers case blockedUsers
case accountSessions case manageAccount(url: URL)
case notifications case notifications
case advancedSettings case advancedSettings
case developerOptions case developerOptions
@ -64,8 +63,8 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.dismiss) actionsSubject.send(.dismiss)
case .userDetails: case .userDetails:
actionsSubject.send(.userDetails) actionsSubject.send(.userDetails)
case .accountProfile: case let .manageAccount(url):
actionsSubject.send(.accountProfile) actionsSubject.send(.manageAccount(url: url))
case .analytics: case .analytics:
actionsSubject.send(.analytics) actionsSubject.send(.analytics)
case .appLock: case .appLock:
@ -78,8 +77,6 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.blockedUsers) actionsSubject.send(.blockedUsers)
case .secureBackup: case .secureBackup:
actionsSubject.send(.secureBackup) actionsSubject.send(.secureBackup)
case .accountSessionsList:
actionsSubject.send(.accountSessions)
case .notifications: case .notifications:
actionsSubject.send(.notifications) actionsSubject.send(.notifications)
case .advancedSettings: case .advancedSettings:

View File

@ -17,17 +17,16 @@
import Foundation import Foundation
import UIKit import UIKit
enum SettingsScreenViewModelAction { enum SettingsScreenViewModelAction: Equatable {
case close case close
case userDetails case userDetails
case accountProfile case manageAccount(url: URL)
case analytics case analytics
case appLock case appLock
case reportBug case reportBug
case about case about
case blockedUsers case blockedUsers
case secureBackup case secureBackup
case accountSessionsList
case notifications case notifications
case advancedSettings case advancedSettings
case developerOptions case developerOptions
@ -57,14 +56,13 @@ struct SettingsScreenViewState: BindableState {
enum SettingsScreenViewAction { enum SettingsScreenViewAction {
case close case close
case userDetails case userDetails
case accountProfile
case analytics case analytics
case appLock case appLock
case reportBug case reportBug
case about case about
case blockedUsers case blockedUsers
case secureBackup case secureBackup
case accountSessionsList case manageAccount(url: URL)
case notifications case notifications
case developerOptions case developerOptions
case advancedSettings case advancedSettings

View File

@ -29,8 +29,6 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
init(userSession: UserSessionProtocol, appSettings: AppSettings) { init(userSession: UserSessionProtocol, appSettings: AppSettings) {
super.init(initialViewState: .init(deviceID: userSession.deviceID, super.init(initialViewState: .init(deviceID: userSession.deviceID,
userID: userSession.userID, userID: userSession.userID,
accountProfileURL: userSession.clientProxy.accountURL(action: .profile),
accountSessionsListURL: userSession.clientProxy.accountURL(action: .sessionsList),
showDeveloperOptions: appSettings.isDevelopmentBuild), showDeveloperOptions: appSettings.isDevelopmentBuild),
imageProvider: userSession.mediaProvider) imageProvider: userSession.mediaProvider)
@ -81,6 +79,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
Task { Task {
await userSession.clientProxy.loadUserAvatarURL() await userSession.clientProxy.loadUserAvatarURL()
await userSession.clientProxy.loadUserDisplayName() await userSession.clientProxy.loadUserDisplayName()
await state.accountProfileURL = userSession.clientProxy.accountURL(action: .profile)
await state.accountSessionsListURL = userSession.clientProxy.accountURL(action: .sessionsList)
} }
} }
@ -90,8 +90,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
actionsSubject.send(.close) actionsSubject.send(.close)
case .userDetails: case .userDetails:
actionsSubject.send(.userDetails) actionsSubject.send(.userDetails)
case .accountProfile: case let .manageAccount(url):
actionsSubject.send(.accountProfile) actionsSubject.send(.manageAccount(url: url))
case .analytics: case .analytics:
actionsSubject.send(.analytics) actionsSubject.send(.analytics)
case .appLock: case .appLock:
@ -108,8 +108,6 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
actionsSubject.send(.secureBackup) actionsSubject.send(.secureBackup)
case .notifications: case .notifications:
actionsSubject.send(.notifications) actionsSubject.send(.notifications)
case .accountSessionsList:
actionsSubject.send(.accountSessionsList)
case .advancedSettings: case .advancedSettings:
actionsSubject.send(.advancedSettings) actionsSubject.send(.advancedSettings)
case .developerOptions: case .developerOptions:

View File

@ -29,9 +29,7 @@ struct SettingsScreen: View {
mainSection mainSection
if context.viewState.accountSessionsListURL != nil {
manageSessionsSection manageSessionsSection
}
advancedOptionsSection advancedOptionsSection
@ -95,11 +93,11 @@ struct SettingsScreen: View {
private var mainSection: some View { private var mainSection: some View {
Section { Section {
if context.viewState.accountProfileURL != nil { if let url = context.viewState.accountProfileURL {
ListRow(label: .default(title: L10n.actionManageAccount, ListRow(label: .default(title: L10n.actionManageAccount,
icon: \.userProfile), icon: \.userProfile),
kind: .button { kind: .button {
context.send(viewAction: .accountProfile) context.send(viewAction: .manageAccount(url: url))
}) })
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.account) .accessibilityIdentifier(A11yIdentifiers.settingsScreen.account)
} }
@ -150,15 +148,18 @@ struct SettingsScreen: View {
} }
} }
@ViewBuilder
private var manageSessionsSection: some View { private var manageSessionsSection: some View {
if let url = context.viewState.accountSessionsListURL {
Section { Section {
ListRow(label: .default(title: L10n.actionManageDevices, ListRow(label: .default(title: L10n.actionManageDevices,
icon: \.devices), icon: \.devices),
kind: .button { kind: .button {
context.send(viewAction: .accountSessionsList) context.send(viewAction: .manageAccount(url: url))
}) })
} }
} }
}
private var advancedOptionsSection: some View { private var advancedOptionsSection: some View {
Section { Section {
@ -252,6 +253,7 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View { static var previews: some View {
NavigationStack { NavigationStack {
SettingsScreen(context: viewModel.context) SettingsScreen(context: viewModel.context)
.snapshot(delay: 1.0)
} }
} }
} }

View File

@ -281,8 +281,8 @@ class ClientProxy: ClientProxyProtocol {
} }
} }
func accountURL(action: AccountManagementAction) -> URL? { func accountURL(action: AccountManagementAction) async -> URL? {
try? client.accountUrl(action: action).flatMap(URL.init(string:)) try? await client.accountUrl(action: action).flatMap(URL.init(string:))
} }
func createDirectRoomIfNeeded(with userID: String, expectedRoomName: String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError> { func createDirectRoomIfNeeded(with userID: String, expectedRoomName: String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError> {

View File

@ -121,7 +121,7 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
func stopSync() func stopSync()
func accountURL(action: AccountManagementAction) -> URL? func accountURL(action: AccountManagementAction) async -> URL?
func createDirectRoomIfNeeded(with userID: String, expectedRoomName: String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError> func createDirectRoomIfNeeded(with userID: String, expectedRoomName: String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError>

View File

@ -49,7 +49,7 @@ packages:
# Element/Matrix dependencies # Element/Matrix dependencies
MatrixRustSDK: MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.1.62 exactVersion: 1.1.63
# path: ../matrix-rust-sdk # path: ../matrix-rust-sdk
Compound: Compound:
url: https://github.com/element-hq/compound-ios url: https://github.com/element-hq/compound-ios