Show an alert when entering an account provider that requires Element Pro. (#4326)

This commit is contained in:
Doug
2025-07-17 13:41:26 +01:00
committed by GitHub
parent 247c7a4617
commit f655fbc28b
30 changed files with 253 additions and 5 deletions
@@ -52,6 +52,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
var homeserver = LoginHomeserver(address: homeserverAddress, loginMode: .unknown)
let client = try await makeClient(homeserverAddress: homeserverAddress)
try await appHooks.elementWellKnownHook.validate(using: client).get()
let loginDetails = await client.homeserverLoginDetails()
MXLog.info("Sliding sync: \(client.slidingSyncVersion())")
@@ -81,6 +82,8 @@ class AuthenticationService: AuthenticationServiceProtocol {
} catch ClientBuildError.SlidingSyncVersion(let error) {
MXLog.info("User entered a homeserver that isn't configured for sliding sync: \(error)")
return .failure(.slidingSyncNotAvailable)
} catch ElementWellKnownError.elementProRequired(let serverName) {
return .failure(.elementProRequired(serverName: serverName))
} catch {
MXLog.error("Failed configuring a server: \(error)")
return .failure(.invalidHomeserverAddress)
@@ -176,6 +179,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
do {
let client = try await makeClient(homeserverAddress: scannedServerName)
try await appHooks.elementWellKnownHook.validate(using: client).get()
try await client.loginWithQrCode(qrCodeData: qrData,
oidcConfiguration: appSettings.oidcConfiguration.rustValue,
progressListener: listener)
@@ -184,6 +188,8 @@ class AuthenticationService: AuthenticationServiceProtocol {
} catch let error as HumanQrLoginError {
MXLog.error("QRCode login error: \(error)")
return .failure(error.serviceError)
} catch ElementWellKnownError.elementProRequired(let serverName) {
return .failure(.elementProRequired(serverName: serverName))
} catch {
MXLog.error("QRCode login unknown error: \(error)")
return .failure(.qrCodeError(.unknown))
@@ -30,6 +30,7 @@ enum AuthenticationServiceError: Error, Equatable {
case slidingSyncNotAvailable
case loginNotSupported
case registrationNotSupported
case elementProRequired(serverName: String)
case accountDeactivated
case failedLoggingIn
case sessionTokenRefreshNotSupported
@@ -0,0 +1,35 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Foundation
import MatrixRustSDK
extension ClientProtocol {
func elementWellKnown() async -> Result<Data, ClientProxyError> {
let serverNameURLString = if let userIDServerName = try? userIdServerName() {
"https://\(userIDServerName)"
} else {
server() ?? homeserver()
}
do {
guard let url = URL(string: serverNameURLString)?.appending(path: "/.well-known/element/element.json") else {
return .failure(.invalidServerName)
}
let response = try await getUrl(url: url.absoluteString)
guard let data = response.data(using: .utf8) else {
return .failure(.invalidResponse)
}
return .success(data)
} catch {
return .failure(.sdkError(error))
}
}
}
@@ -34,6 +34,7 @@ enum ClientProxyError: Error {
case invalidMedia
case invalidServerName
case invalidResponse
case failedUploadingMedia(ErrorKind)
case roomPreviewIsPrivate
case failedRetrievingUserIdentity