Make Element Call widget URL configurable (#2971)

This commit is contained in:
Stefan Ceriu
2024-07-02 11:35:05 +03:00
committed by GitHub
parent 78b0c7068d
commit b2c9878df6
15 changed files with 342 additions and 114 deletions
@@ -21,6 +21,7 @@ import OrderedCollections
import MatrixRustSDK
// swiftlint:disable file_length
class ClientProxy: ClientProxyProtocol {
private let client: ClientProtocol
private let networkMonitor: NetworkMonitorProtocol
@@ -188,19 +189,6 @@ class ClientProxy: ClientProxyProtocol {
.store(in: &cancellables)
}
private func updateVerificationState(_ verificationState: VerificationState) {
let verificationState: SessionVerificationState = switch verificationState {
case .unknown:
.unknown
case .unverified:
.unverified
case .verified:
.verified
}
verificationStateSubject.send(verificationState)
}
var userID: String {
do {
return try client.userId()
@@ -214,7 +202,7 @@ class ClientProxy: ClientProxyProtocol {
do {
return try client.deviceId()
} catch {
MXLog.error("Failed retrieving device id with error: \(error)")
MXLog.error("Failed retrieving deviceID with error: \(error)")
return nil
}
}
@@ -222,6 +210,15 @@ class ClientProxy: ClientProxyProtocol {
var homeserver: String {
client.homeserver()
}
var userIDServerName: String? {
do {
return try client.userIdServerName()
} catch {
MXLog.error("Failed retrieving userID server name with error: \(error)")
return nil
}
}
private(set) lazy var pusherNotificationClientIdentifier: String? = {
// NOTE: The result is stored as part of the restoration token. Any changes
@@ -616,6 +613,23 @@ class ClientProxy: ClientProxyProtocol {
return .failure(.sdkError(error))
}
}
func getElementWellKnown() async -> Result<ElementWellKnown?, ClientProxyError> {
guard let userIDServerName,
var url = URL(string: userIDServerName) else {
return .failure(.invalidUserIDServerName)
}
url.append(path: "/.well-known/element/element.json")
do {
let response = try await client.getUrl(url: url.absoluteString)
let sdkWellKnown = try makeElementWellKnown(string: response)
return .success(ElementWellKnown(sdkWellKnown))
} catch {
return .failure(.sdkError(error))
}
}
// MARK: Ignored users
@@ -691,6 +705,19 @@ class ClientProxy: ClientProxyProtocol {
}
// MARK: - Private
private func updateVerificationState(_ verificationState: VerificationState) {
let verificationState: SessionVerificationState = switch verificationState {
case .unknown:
.unknown
case .unverified:
.unverified
case .verified:
.verified
}
verificationStateSubject.send(verificationState)
}
private func loadUserAvatarURLFromCache() {
loadCachedAvatarURLTask = Task {
@@ -41,6 +41,7 @@ enum ClientProxyError: Error {
case sdkError(Error)
case invalidMedia
case invalidUserIDServerName
case failedUploadingMedia(Error, MatrixErrorCode)
}
@@ -94,6 +95,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
var deviceID: String? { get }
var homeserver: String { get }
var userIDServerName: String? { get }
var userDisplayNamePublisher: CurrentValuePublisher<String?, Never> { get }
@@ -162,6 +165,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
func roomDirectorySearchProxy() -> RoomDirectorySearchProxyProtocol
func resolveRoomAlias(_ alias: String) async -> Result<ResolvedRoomAlias, ClientProxyError>
func getElementWellKnown() async -> Result<ElementWellKnown?, ClientProxyError>
// MARK: - Ignored users
@@ -0,0 +1,35 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import MatrixRustSDK
struct ElementWellKnown {
struct Call {
let widgetURL: URL
init?(_ wellKnown: MatrixRustSDK.ElementCallWellKnown) {
guard let widgetURL = URL(string: wellKnown.widgetUrl) else { return nil }
self.widgetURL = widgetURL
}
}
let call: Call?
init?(_ wellKnown: MatrixRustSDK.ElementWellKnown) {
call = Call(wellKnown.call)
}
}