mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Make the remote settings hook usable within the app extensions. (#4342)
This commit is contained in:
@@ -52,7 +52,6 @@ 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())")
|
||||
@@ -82,7 +81,7 @@ 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) {
|
||||
} catch RemoteSettingsError.elementProRequired(let serverName) {
|
||||
return .failure(.elementProRequired(serverName: serverName))
|
||||
} catch {
|
||||
MXLog.error("Failed configuring a server: \(error)")
|
||||
@@ -179,7 +178,6 @@ 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)
|
||||
@@ -188,7 +186,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
|
||||
} catch let error as HumanQrLoginError {
|
||||
MXLog.error("QRCode login error: \(error)")
|
||||
return .failure(error.serviceError)
|
||||
} catch ElementWellKnownError.elementProRequired(let serverName) {
|
||||
} catch RemoteSettingsError.elementProRequired(let serverName) {
|
||||
return .failure(.elementProRequired(serverName: serverName))
|
||||
} catch {
|
||||
MXLog.error("QRCode login unknown error: \(error)")
|
||||
@@ -209,12 +207,15 @@ class AuthenticationService: AuthenticationServiceProtocol {
|
||||
// so that caches (e.g. server versions) are always fresh for the new server.
|
||||
rotateSessionDirectory()
|
||||
|
||||
return try await clientFactory.makeClient(homeserverAddress: homeserverAddress,
|
||||
sessionDirectories: sessionDirectories,
|
||||
passphrase: passphrase,
|
||||
clientSessionDelegate: userSessionStore.clientSessionDelegate,
|
||||
appSettings: appSettings,
|
||||
appHooks: appHooks)
|
||||
let client = try await clientFactory.makeClient(homeserverAddress: homeserverAddress,
|
||||
sessionDirectories: sessionDirectories,
|
||||
passphrase: passphrase,
|
||||
clientSessionDelegate: userSessionStore.clientSessionDelegate,
|
||||
appSettings: appSettings,
|
||||
appHooks: appHooks)
|
||||
try await appHooks.remoteSettingsHook.initializeCache(using: client, applyingTo: appSettings).get()
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
private func rotateSessionDirectory() {
|
||||
|
||||
@@ -46,13 +46,6 @@ enum BugReportServiceError: LocalizedError {
|
||||
}
|
||||
}
|
||||
|
||||
enum RageshakeConfiguration: Equatable {
|
||||
/// Rageshakes should be sent to the provided URL
|
||||
case url(URL)
|
||||
/// Rageshakes are disabled.
|
||||
case disabled
|
||||
}
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol BugReportServiceProtocol: AnyObject {
|
||||
var isEnabled: Bool { get }
|
||||
|
||||
@@ -117,6 +117,7 @@ class UserSessionStore: UserSessionStoreProtocol {
|
||||
}
|
||||
|
||||
let homeserverURL = credentials.restorationToken.session.homeserverUrl
|
||||
appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: appSettings)
|
||||
|
||||
let builder = ClientBuilder
|
||||
.baseBuilder(httpProxy: URL(string: homeserverURL)?.globalProxy,
|
||||
@@ -134,11 +135,12 @@ class UserSessionStore: UserSessionStoreProtocol {
|
||||
|
||||
do {
|
||||
let client = try await builder.build()
|
||||
|
||||
try await client.restoreSession(session: credentials.restorationToken.session)
|
||||
|
||||
MXLog.info("Set up session for user \(credentials.userID) at: \(credentials.restorationToken.sessionDirectories)")
|
||||
|
||||
Task(priority: .low) { await appHooks.remoteSettingsHook.updateCache(using: client) }
|
||||
|
||||
return try await .success(setupProxyForClient(client, needsSlidingSyncMigration: credentials.restorationToken.needsSlidingSyncMigration))
|
||||
} catch UserSessionStoreError.failedSettingUpClientProxy(let error) {
|
||||
// If this has failed, there is likely something wrong with the creation of the sync service
|
||||
|
||||
Reference in New Issue
Block a user