mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Use server name from user id function (#6082)
update sdk and use the new server from user id function from the sdk
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
typealias LoginScreenViewModelType = StateStoreViewModelV2<LoginScreenViewState, LoginScreenViewAction>
|
||||
@@ -66,9 +67,7 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc
|
||||
private func parseUsername() {
|
||||
let username = state.bindings.username
|
||||
|
||||
guard MatrixEntityRegex.isMatrixUserIdentifier(username) else { return }
|
||||
|
||||
let homeserverDomain = String(username.split(separator: ":")[1])
|
||||
guard let homeserverDomain = try? serverNameFromUserId(userId: username) else { return }
|
||||
|
||||
startLoading(isInteractionBlocking: false)
|
||||
|
||||
|
||||
+4
-1
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
typealias ServerSelectionScreenViewModelType = StateStoreViewModelV2<ServerSelectionScreenViewState, ServerSelectionScreenViewAction>
|
||||
@@ -101,7 +102,9 @@ class ServerSelectionScreenViewModel: ServerSelectionScreenViewModelType, Server
|
||||
|
||||
/// Updates the login flow using the supplied homeserver address, or shows an error when this isn't possible.
|
||||
private func configureHomeserver() async {
|
||||
let homeserverAddress = state.bindings.homeserverAddress
|
||||
let userInput = state.bindings.homeserverAddress
|
||||
// People often enter their Matrix ID here, so use the server name from it when they do.
|
||||
let homeserverAddress = (try? serverNameFromUserId(userId: userInput)) ?? userInput
|
||||
startLoading()
|
||||
|
||||
switch await authenticationService.configure(for: homeserverAddress, flow: authenticationFlow) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
class ClassicAppAccountManager {
|
||||
private let cacheFolder: URL
|
||||
@@ -64,7 +65,7 @@ class ClassicAppAccountManager {
|
||||
let userID = mxAccount.userID
|
||||
let user = loadUser(for: mxAccount) // We need an MXUser for the profile as MXAccount doesn't contain that data.
|
||||
|
||||
guard let serverName = serverName(for: userID) else { return nil }
|
||||
guard let serverName = try? serverNameFromUserId(userId: userID) else { return nil }
|
||||
|
||||
return ClassicAppAccount(userID: userID,
|
||||
displayName: user?.displayName,
|
||||
@@ -103,13 +104,6 @@ class ClassicAppAccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// The server name extracted from the user's ID.
|
||||
private func serverName(for userID: String) -> String? {
|
||||
let components = userID.components(separatedBy: ":")
|
||||
guard components.count > 1 else { return nil }
|
||||
return components[1] // Directly use [1] as .last may be the port number.
|
||||
}
|
||||
|
||||
// MARK: - File URLs
|
||||
|
||||
private static let matrixKitFolder = "MatrixKit"
|
||||
|
||||
@@ -212,7 +212,7 @@ extension JoinedRoomProxyProtocol {
|
||||
func knownServerNames(maxCount: Int) -> any Sequence<String> {
|
||||
membersPublisher.value
|
||||
.prefix(1000) // No need to go crazy here…
|
||||
.compactMap { $0.userID.split(separator: ":").last.map(String.init) }
|
||||
.compactMap { try? serverNameFromUserId(userId: $0.userID) }
|
||||
.uniqued()
|
||||
.prefix(maxCount)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user