Base ElementCall encryption on the room encryption state, remove developer options setting

This commit is contained in:
Stefan Ceriu
2024-02-01 16:37:03 +02:00
committed by Stefan Ceriu
parent 497177ee65
commit 7aa81f542c
11 changed files with 25 additions and 37 deletions
@@ -231,9 +231,6 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.elementCallBaseURL, defaultValue: "https://call.element.io", storageType: .userDefaults(store)) @UserPreference(key: UserDefaultsKeys.elementCallBaseURL, defaultValue: "https://call.element.io", storageType: .userDefaults(store))
var elementCallBaseURL: URL var elementCallBaseURL: URL
@UserPreference(key: UserDefaultsKeys.elementCallEncryptionEnabled, defaultValue: true, storageType: .userDefaults(store))
var elementCallUseEncryption
// MARK: - Notifications // MARK: - Notifications
@UserPreference(key: UserDefaultsKeys.enableNotifications, defaultValue: true, storageType: .userDefaults(store)) @UserPreference(key: UserDefaultsKeys.enableNotifications, defaultValue: true, storageType: .userDefaults(store))
@@ -495,8 +495,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
private func presentCallScreen(roomProxy: RoomProxyProtocol) { private func presentCallScreen(roomProxy: RoomProxyProtocol) {
let callScreenCoordinator = CallScreenCoordinator(parameters: .init(roomProxy: roomProxy, let callScreenCoordinator = CallScreenCoordinator(parameters: .init(roomProxy: roomProxy,
callBaseURL: appSettings.elementCallBaseURL, callBaseURL: appSettings.elementCallBaseURL,
clientID: InfoPlistReader.main.bundleIdentifier, clientID: InfoPlistReader.main.bundleIdentifier))
useEncryption: appSettings.elementCallUseEncryption))
callScreenCoordinator.actions callScreenCoordinator.actions
.sink { [weak self] action in .sink { [weak self] action in
@@ -754,23 +754,23 @@ class ElementCallWidgetDriverMock: ElementCallWidgetDriverProtocol {
//MARK: - start //MARK: - start
var startBaseURLClientIDUseEncryptionCallsCount = 0 var startBaseURLClientIDCallsCount = 0
var startBaseURLClientIDUseEncryptionCalled: Bool { var startBaseURLClientIDCalled: Bool {
return startBaseURLClientIDUseEncryptionCallsCount > 0 return startBaseURLClientIDCallsCount > 0
} }
var startBaseURLClientIDUseEncryptionReceivedArguments: (baseURL: URL, clientID: String, useEncryption: Bool)? var startBaseURLClientIDReceivedArguments: (baseURL: URL, clientID: String)?
var startBaseURLClientIDUseEncryptionReceivedInvocations: [(baseURL: URL, clientID: String, useEncryption: Bool)] = [] var startBaseURLClientIDReceivedInvocations: [(baseURL: URL, clientID: String)] = []
var startBaseURLClientIDUseEncryptionReturnValue: Result<URL, ElementCallWidgetDriverError>! var startBaseURLClientIDReturnValue: Result<URL, ElementCallWidgetDriverError>!
var startBaseURLClientIDUseEncryptionClosure: ((URL, String, Bool) async -> Result<URL, ElementCallWidgetDriverError>)? var startBaseURLClientIDClosure: ((URL, String) async -> Result<URL, ElementCallWidgetDriverError>)?
func start(baseURL: URL, clientID: String, useEncryption: Bool) async -> Result<URL, ElementCallWidgetDriverError> { func start(baseURL: URL, clientID: String) async -> Result<URL, ElementCallWidgetDriverError> {
startBaseURLClientIDUseEncryptionCallsCount += 1 startBaseURLClientIDCallsCount += 1
startBaseURLClientIDUseEncryptionReceivedArguments = (baseURL: baseURL, clientID: clientID, useEncryption: useEncryption) startBaseURLClientIDReceivedArguments = (baseURL: baseURL, clientID: clientID)
startBaseURLClientIDUseEncryptionReceivedInvocations.append((baseURL: baseURL, clientID: clientID, useEncryption: useEncryption)) startBaseURLClientIDReceivedInvocations.append((baseURL: baseURL, clientID: clientID))
if let startBaseURLClientIDUseEncryptionClosure = startBaseURLClientIDUseEncryptionClosure { if let startBaseURLClientIDClosure = startBaseURLClientIDClosure {
return await startBaseURLClientIDUseEncryptionClosure(baseURL, clientID, useEncryption) return await startBaseURLClientIDClosure(baseURL, clientID)
} else { } else {
return startBaseURLClientIDUseEncryptionReturnValue return startBaseURLClientIDReturnValue
} }
} }
//MARK: - sendMessage //MARK: - sendMessage
+1 -1
View File
@@ -96,7 +96,7 @@ extension RoomProxyMock {
fatalError() fatalError()
} }
widgetDriver.startBaseURLClientIDUseEncryptionReturnValue = .success(url) widgetDriver.startBaseURLClientIDReturnValue = .success(url)
elementCallWidgetDriverReturnValue = widgetDriver elementCallWidgetDriverReturnValue = widgetDriver
} }
@@ -23,8 +23,6 @@ struct CallScreenCoordinatorParameters {
let callBaseURL: URL let callBaseURL: URL
/// A way to identify the current client against Element Call /// A way to identify the current client against Element Call
let clientID: String let clientID: String
/// Whether encryption should be used within the call
let useEncryption: Bool
} }
enum CallScreenCoordinatorAction { enum CallScreenCoordinatorAction {
@@ -43,8 +41,7 @@ final class CallScreenCoordinator: CoordinatorProtocol {
init(parameters: CallScreenCoordinatorParameters) { init(parameters: CallScreenCoordinatorParameters) {
viewModel = CallScreenViewModel(roomProxy: parameters.roomProxy, viewModel = CallScreenViewModel(roomProxy: parameters.roomProxy,
callBaseURL: parameters.callBaseURL, callBaseURL: parameters.callBaseURL,
clientID: parameters.clientID, clientID: parameters.clientID)
useEncryption: parameters.useEncryption)
} }
func start() { func start() {
@@ -48,8 +48,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
/// - clientID: Something to identify the current client on the Element Call side /// - clientID: Something to identify the current client on the Element Call side
init(roomProxy: RoomProxyProtocol, init(roomProxy: RoomProxyProtocol,
callBaseURL: URL, callBaseURL: URL,
clientID: String, clientID: String) {
useEncryption: Bool) {
self.roomProxy = roomProxy self.roomProxy = roomProxy
widgetDriver = roomProxy.elementCallWidgetDriver() widgetDriver = roomProxy.elementCallWidgetDriver()
@@ -98,7 +97,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
.store(in: &cancellables) .store(in: &cancellables)
Task { Task {
switch await widgetDriver.start(baseURL: callBaseURL, clientID: clientID, useEncryption: useEncryption) { switch await widgetDriver.start(baseURL: callBaseURL, clientID: clientID) {
case .success(let url): case .success(let url):
state.url = url state.url = url
case .failure(let error): case .failure(let error):
@@ -163,14 +163,13 @@ struct CallScreen_Previews: PreviewProvider {
let widgetDriver = ElementCallWidgetDriverMock() let widgetDriver = ElementCallWidgetDriverMock()
widgetDriver.underlyingMessagePublisher = .init() widgetDriver.underlyingMessagePublisher = .init()
widgetDriver.underlyingActions = PassthroughSubject<ElementCallWidgetDriverAction, Never>().eraseToAnyPublisher() widgetDriver.underlyingActions = PassthroughSubject<ElementCallWidgetDriverAction, Never>().eraseToAnyPublisher()
widgetDriver.startBaseURLClientIDUseEncryptionReturnValue = .success(URL.userDirectory) widgetDriver.startBaseURLClientIDReturnValue = .success(URL.userDirectory)
roomProxy.elementCallWidgetDriverReturnValue = widgetDriver roomProxy.elementCallWidgetDriverReturnValue = widgetDriver
return CallScreenViewModel(roomProxy: roomProxy, return CallScreenViewModel(roomProxy: roomProxy,
callBaseURL: "https://call.element.io", callBaseURL: "https://call.element.io",
clientID: "io.element.elementx", clientID: "io.element.elementx")
useEncryption: false)
}() }()
static var previews: some View { static var previews: some View {
@@ -53,7 +53,6 @@ protocol DeveloperOptionsProtocol: AnyObject {
var roomListFiltersEnabled: Bool { get set } var roomListFiltersEnabled: Bool { get set }
var elementCallBaseURL: URL { get set } var elementCallBaseURL: URL { get set }
var elementCallUseEncryption: Bool { get set }
} }
extension AppSettings: DeveloperOptionsProtocol { } extension AppSettings: DeveloperOptionsProtocol { }
@@ -75,10 +75,6 @@ struct DeveloperOptionsScreen: View {
.autocorrectionDisabled(true) .autocorrectionDisabled(true)
.autocapitalization(.none) .autocapitalization(.none)
.foregroundColor(URL(string: elementCallBaseURLString) == nil ? .red : .primary) .foregroundColor(URL(string: elementCallBaseURLString) == nil ? .red : .primary)
Toggle(isOn: $context.elementCallUseEncryption) {
Text("Use encryption")
}
} }
Section { Section {
@@ -52,11 +52,13 @@ class ElementCallWidgetDriver: WidgetCapabilitiesProvider, ElementCallWidgetDriv
self.room = room self.room = room
} }
func start(baseURL: URL, clientID: String, useEncryption: Bool) async -> Result<URL, ElementCallWidgetDriverError> { func start(baseURL: URL, clientID: String) async -> Result<URL, ElementCallWidgetDriverError> {
guard let room = room as? Room else { guard let room = room as? Room else {
return .failure(.roomInvalid) return .failure(.roomInvalid)
} }
let useEncryption = (try? room.isEncrypted()) ?? false
guard let widgetSettings = try? newVirtualElementCallWidget(props: .init(elementCallUrl: baseURL.absoluteString, guard let widgetSettings = try? newVirtualElementCallWidget(props: .init(elementCallUrl: baseURL.absoluteString,
widgetId: UUID().uuidString, widgetId: UUID().uuidString,
parentUrl: nil, parentUrl: nil,
@@ -35,7 +35,7 @@ protocol ElementCallWidgetDriverProtocol {
var messagePublisher: PassthroughSubject<String, Never> { get } var messagePublisher: PassthroughSubject<String, Never> { get }
var actions: AnyPublisher<ElementCallWidgetDriverAction, Never> { get } var actions: AnyPublisher<ElementCallWidgetDriverAction, Never> { get }
func start(baseURL: URL, clientID: String, useEncryption: Bool) async -> Result<URL, ElementCallWidgetDriverError> func start(baseURL: URL, clientID: String) async -> Result<URL, ElementCallWidgetDriverError>
func sendMessage(_ message: String) async -> Result<Bool, ElementCallWidgetDriverError> func sendMessage(_ message: String) async -> Result<Bool, ElementCallWidgetDriverError>
} }