mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Configure SDK to use the global/OS proxy (#2493)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// DO NOT EDIT
|
||||
|
||||
// swiftlint:disable all
|
||||
@@ -371,16 +371,37 @@ class SDKClientMock: SDKClientProtocol {
|
||||
}
|
||||
public var ignoreUserUserIdReceivedUserId: String?
|
||||
public var ignoreUserUserIdReceivedInvocations: [String] = []
|
||||
public var ignoreUserUserIdClosure: ((String) throws -> Void)?
|
||||
public var ignoreUserUserIdClosure: ((String) async throws -> Void)?
|
||||
|
||||
public func ignoreUser(userId: String) throws {
|
||||
public func ignoreUser(userId: String) async throws {
|
||||
if let error = ignoreUserUserIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
ignoreUserUserIdCallsCount += 1
|
||||
ignoreUserUserIdReceivedUserId = userId
|
||||
ignoreUserUserIdReceivedInvocations.append(userId)
|
||||
try ignoreUserUserIdClosure?(userId)
|
||||
try await ignoreUserUserIdClosure?(userId)
|
||||
}
|
||||
//MARK: - ignoredUsers
|
||||
|
||||
public var ignoredUsersThrowableError: Error?
|
||||
public var ignoredUsersCallsCount = 0
|
||||
public var ignoredUsersCalled: Bool {
|
||||
return ignoredUsersCallsCount > 0
|
||||
}
|
||||
public var ignoredUsersReturnValue: [String]!
|
||||
public var ignoredUsersClosure: (() async throws -> [String])?
|
||||
|
||||
public func ignoredUsers() async throws -> [String] {
|
||||
if let error = ignoredUsersThrowableError {
|
||||
throw error
|
||||
}
|
||||
ignoredUsersCallsCount += 1
|
||||
if let ignoredUsersClosure = ignoredUsersClosure {
|
||||
return try await ignoredUsersClosure()
|
||||
} else {
|
||||
return ignoredUsersReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - login
|
||||
|
||||
@@ -628,6 +649,27 @@ class SDKClientMock: SDKClientProtocol {
|
||||
setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedInvocations.append((identifiers: identifiers, kind: kind, appDisplayName: appDisplayName, deviceDisplayName: deviceDisplayName, profileTag: profileTag, lang: lang))
|
||||
try setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangClosure?(identifiers, kind, appDisplayName, deviceDisplayName, profileTag, lang)
|
||||
}
|
||||
//MARK: - subscribeToIgnoredUsers
|
||||
|
||||
public var subscribeToIgnoredUsersListenerCallsCount = 0
|
||||
public var subscribeToIgnoredUsersListenerCalled: Bool {
|
||||
return subscribeToIgnoredUsersListenerCallsCount > 0
|
||||
}
|
||||
public var subscribeToIgnoredUsersListenerReceivedListener: IgnoredUsersListener?
|
||||
public var subscribeToIgnoredUsersListenerReceivedInvocations: [IgnoredUsersListener] = []
|
||||
public var subscribeToIgnoredUsersListenerReturnValue: TaskHandle!
|
||||
public var subscribeToIgnoredUsersListenerClosure: ((IgnoredUsersListener) -> TaskHandle)?
|
||||
|
||||
public func subscribeToIgnoredUsers(listener: IgnoredUsersListener) -> TaskHandle {
|
||||
subscribeToIgnoredUsersListenerCallsCount += 1
|
||||
subscribeToIgnoredUsersListenerReceivedListener = listener
|
||||
subscribeToIgnoredUsersListenerReceivedInvocations.append(listener)
|
||||
if let subscribeToIgnoredUsersListenerClosure = subscribeToIgnoredUsersListenerClosure {
|
||||
return subscribeToIgnoredUsersListenerClosure(listener)
|
||||
} else {
|
||||
return subscribeToIgnoredUsersListenerReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - syncService
|
||||
|
||||
public var syncServiceCallsCount = 0
|
||||
@@ -654,16 +696,16 @@ class SDKClientMock: SDKClientProtocol {
|
||||
}
|
||||
public var unignoreUserUserIdReceivedUserId: String?
|
||||
public var unignoreUserUserIdReceivedInvocations: [String] = []
|
||||
public var unignoreUserUserIdClosure: ((String) throws -> Void)?
|
||||
public var unignoreUserUserIdClosure: ((String) async throws -> Void)?
|
||||
|
||||
public func unignoreUser(userId: String) throws {
|
||||
public func unignoreUser(userId: String) async throws {
|
||||
if let error = unignoreUserUserIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
unignoreUserUserIdCallsCount += 1
|
||||
unignoreUserUserIdReceivedUserId = userId
|
||||
unignoreUserUserIdReceivedInvocations.append(userId)
|
||||
try unignoreUserUserIdClosure?(userId)
|
||||
try await unignoreUserUserIdClosure?(userId)
|
||||
}
|
||||
//MARK: - uploadAvatar
|
||||
|
||||
|
||||
@@ -67,4 +67,17 @@ extension URL: ExpressibleByStringLiteral {
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
var globalProxy: String? {
|
||||
if let proxySettingsUnmanaged = CFNetworkCopySystemProxySettings() {
|
||||
let proxySettings = proxySettingsUnmanaged.takeRetainedValue()
|
||||
let proxiesUnmanaged = CFNetworkCopyProxiesForURL(self as CFURL, proxySettings)
|
||||
if let proxy = (proxiesUnmanaged.takeRetainedValue() as? [[AnyHashable: Any]])?.first,
|
||||
let hostname = proxy[kCFProxyHostNameKey] as? String,
|
||||
let port = proxy[kCFProxyPortNumberKey] as? Int {
|
||||
return "\(hostname):\(port)"
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +46,12 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
|
||||
policyUri: appSettings.privacyURL.absoluteString,
|
||||
contacts: [appSettings.supportEmailAddress],
|
||||
staticRegistrations: appSettings.oidcStaticRegistrations.mapKeys { $0.absoluteString })
|
||||
|
||||
|
||||
authenticationService = AuthenticationService(basePath: userSessionStore.baseDirectory.path,
|
||||
passphrase: passphrase,
|
||||
userAgent: UserAgentBuilder.makeASCIIUserAgent(),
|
||||
additionalRootCertificates: [],
|
||||
proxy: appSettings.websiteURL.globalProxy,
|
||||
oidcConfiguration: oidcConfiguration,
|
||||
customSlidingSyncProxy: appSettings.slidingSyncProxyURL?.absoluteString,
|
||||
sessionDelegate: userSessionStore.clientSessionDelegate,
|
||||
|
||||
@@ -242,13 +242,11 @@ class RoomProxy: RoomProxyProtocol {
|
||||
sendMessageBackgroundTask?.stop()
|
||||
}
|
||||
|
||||
return await Task.dispatch(on: userInitiatedDispatchQueue) {
|
||||
do {
|
||||
try self.room.ignoreUser(userId: userID)
|
||||
return .success(())
|
||||
} catch {
|
||||
return .failure(.failedReportingContent)
|
||||
}
|
||||
do {
|
||||
try await room.ignoreUser(userId: userID)
|
||||
return .success(())
|
||||
} catch {
|
||||
return .failure(.failedIgnoringUser)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import MatrixRustSDK
|
||||
enum RoomProxyError: Error, Equatable {
|
||||
case failedRedactingEvent
|
||||
case failedReportingContent
|
||||
case failedIgnoringUser
|
||||
case failedRetrievingMember
|
||||
case failedLeavingRoom
|
||||
case failedAcceptingInvite
|
||||
|
||||
@@ -115,19 +115,28 @@ class UserSessionStore: UserSessionStoreProtocol {
|
||||
if credentials.restorationToken.passphrase != nil {
|
||||
MXLog.info("Restoring client with encrypted store.")
|
||||
}
|
||||
let builder = ClientBuilder()
|
||||
|
||||
let homeserverURL = credentials.restorationToken.session.homeserverUrl
|
||||
|
||||
var builder = ClientBuilder()
|
||||
.basePath(path: baseDirectory.path)
|
||||
.username(username: credentials.userID)
|
||||
.homeserverUrl(url: credentials.restorationToken.session.homeserverUrl)
|
||||
.homeserverUrl(url: homeserverURL)
|
||||
.passphrase(passphrase: credentials.restorationToken.passphrase)
|
||||
.userAgent(userAgent: UserAgentBuilder.makeASCIIUserAgent())
|
||||
.enableCrossProcessRefreshLock(processId: InfoPlistReader.main.bundleIdentifier,
|
||||
sessionDelegate: keychainController)
|
||||
.serverVersions(versions: ["v1.0", "v1.1", "v1.2", "v1.3", "v1.4", "v1.5"]) // FIXME: Quick and dirty fix for stopping version requests on startup https://github.com/matrix-org/matrix-rust-sdk/pull/1376
|
||||
|
||||
|
||||
if let homeserverURL = URL(string: homeserverURL),
|
||||
let proxy = homeserverURL.globalProxy {
|
||||
builder = builder.proxy(url: proxy)
|
||||
}
|
||||
let completeBuilder = builder
|
||||
|
||||
do {
|
||||
let client: Client = try await Task.dispatch(on: .global()) {
|
||||
let client = try builder.build()
|
||||
let client = try completeBuilder.build()
|
||||
try client.restoreSession(session: credentials.restorationToken.session)
|
||||
return client
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user