mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Security and privacy part 2 (#3637)
* handling the history visibility flag * better logic to handle visibility * better handling of the visibility options state * added some copies, and the public room directory visibility state * completed the UI added also the preview tests * improved the handling of the directory visibility * added the space users case and improved handling of the access -> vsibility reaction. Also added a simple error handling for the public directory toggle * added the edit room address view but is missing its full implementation * implement the UI for the edit room address screen * implemented error checking when editing the address * updated preview tests and improved code * typo fix * Fix various issues after rebasing. * Fix build errors and broken snapshot tests * Adopt latest room privacy and canonical alias setting APIs * Add support for creating and editing the room's alias. * Add support for saving room privacy setting changes. * Fix room alias screen snapshot tests following recent changes. --------- Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
@@ -72,3 +72,14 @@ enum CreateRoomAliasErrorState {
|
||||
case alreadyExists
|
||||
case invalidSymbols
|
||||
}
|
||||
|
||||
extension Set<CreateRoomAliasErrorState> {
|
||||
var errorDescription: String? {
|
||||
if contains(.alreadyExists) {
|
||||
return L10n.errorRoomAddressAlreadyExists
|
||||
} else if contains(.invalidSymbols) {
|
||||
return L10n.errorRoomAddressInvalidSymbols
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,8 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
||||
|
||||
guard state.isKnockingFeatureEnabled,
|
||||
!state.bindings.isRoomPrivate,
|
||||
let canonicalAlias = canonicalAlias(aliasLocalPart: aliasLocalPart) else {
|
||||
let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: aliasLocalPart,
|
||||
serverName: state.serverName) else {
|
||||
// While is empty or private room we don't change or display the error
|
||||
return
|
||||
}
|
||||
@@ -209,8 +210,9 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
||||
|
||||
// Better to double check the errors also when trying to create the room
|
||||
if state.isKnockingFeatureEnabled, !createRoomParameters.isRoomPrivate {
|
||||
guard let canonicalAlias = canonicalAlias(aliasLocalPart: createRoomParameters.aliasLocalPart),
|
||||
isRoomAliasFormatValid(alias: canonicalAlias) else {
|
||||
guard let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: createRoomParameters.aliasLocalPart,
|
||||
serverName: state.serverName),
|
||||
isRoomAliasFormatValid(alias: canonicalAlias) else {
|
||||
state.aliasErrors = [.invalidSymbols]
|
||||
return
|
||||
}
|
||||
@@ -271,14 +273,6 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
||||
}
|
||||
}
|
||||
|
||||
func canonicalAlias(aliasLocalPart: String?) -> String? {
|
||||
guard let aliasLocalPart,
|
||||
!aliasLocalPart.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
return "#\(aliasLocalPart):\(state.serverName)"
|
||||
}
|
||||
|
||||
// MARK: Loading indicator
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(CreateRoomViewModel.self)-Loading"
|
||||
|
||||
@@ -190,35 +190,17 @@ struct CreateRoomScreen: View {
|
||||
|
||||
private var roomAliasSection: some View {
|
||||
Section {
|
||||
ListRow(kind: .custom {
|
||||
HStack(spacing: 0) {
|
||||
Text("#")
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
TextField("", text: aliasBinding)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
.textContentType(.URL)
|
||||
.focused($focus, equals: .alias)
|
||||
.tint(.compound.iconAccentTertiary)
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textPrimary)
|
||||
.padding(.horizontal, 8)
|
||||
Text(":\(context.viewState.serverName)")
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
}
|
||||
.padding(ListRowPadding.textFieldInsets)
|
||||
.environment(\.layoutDirection, .leftToRight)
|
||||
.errorBackground(!context.viewState.aliasErrors.isEmpty)
|
||||
})
|
||||
.id(Focus.alias)
|
||||
EditRoomAddressListRow(aliasLocalPart: aliasBinding,
|
||||
serverName: context.viewState.serverName,
|
||||
shouldDisplayError: context.viewState.aliasErrors.errorDescription != nil)
|
||||
.focused($focus, equals: .alias)
|
||||
.id(Focus.alias)
|
||||
} header: {
|
||||
Text(L10n.screenCreateRoomRoomAddressSectionTitle)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if let errorDescription = context.viewState.aliasErrorDescription {
|
||||
if let errorDescription = context.viewState.aliasErrors.errorDescription {
|
||||
Label(errorDescription, icon: \.error, iconSize: .xSmall, relativeTo: .compound.bodySM)
|
||||
.foregroundStyle(.compound.textCriticalPrimary)
|
||||
.font(.compound.bodySM)
|
||||
@@ -241,15 +223,6 @@ struct CreateRoomScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private extension View {
|
||||
func errorBackground(_ shouldDisplay: Bool) -> some View {
|
||||
listRowBackground(shouldDisplay ? AnyView(RoundedRectangle(cornerRadius: 10)
|
||||
.inset(by: 1)
|
||||
.fill(.compound.bgCriticalSubtleHovered)
|
||||
.stroke(Color.compound.borderCriticalPrimary)) : AnyView(Color.compound.bgCanvasDefaultLevel1))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct CreateRoom_Previews: PreviewProvider, TestablePreview {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
// periphery:ignore:all - this is just a editRoomAddress remove this comment once generating the final file
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct EditRoomAddressScreenCoordinatorParameters {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum EditRoomAddressScreenCoordinatorAction {
|
||||
case dismiss
|
||||
}
|
||||
|
||||
final class EditRoomAddressScreenCoordinator: CoordinatorProtocol {
|
||||
private let viewModel: EditRoomAddressScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private let actionsSubject: PassthroughSubject<EditRoomAddressScreenCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<EditRoomAddressScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(parameters: EditRoomAddressScreenCoordinatorParameters) {
|
||||
viewModel = EditRoomAddressScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
clientProxy: parameters.clientProxy,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
viewModel.actionsPublisher.sink { [weak self] action in
|
||||
MXLog.info("Coordinator: received view model action: \(action)")
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .dismiss:
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(EditRoomAddressScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum EditRoomAddressScreenViewModelAction {
|
||||
case dismiss
|
||||
}
|
||||
|
||||
struct EditRoomAddressScreenViewState: BindableState {
|
||||
let serverName: String
|
||||
var currentAliasLocalPart: String?
|
||||
var aliasErrors: Set<EditRoomAddressErrorState> = []
|
||||
|
||||
var canSave: Bool {
|
||||
currentAliasLocalPart != bindings.desiredAliasLocalPart &&
|
||||
aliasErrors.isEmpty &&
|
||||
!bindings.desiredAliasLocalPart.isEmpty
|
||||
}
|
||||
|
||||
var bindings: EditRoomAddressScreenViewStateBindings
|
||||
}
|
||||
|
||||
struct EditRoomAddressScreenViewStateBindings {
|
||||
var desiredAliasLocalPart: String
|
||||
}
|
||||
|
||||
enum EditRoomAddressScreenViewAction {
|
||||
case save
|
||||
case cancel
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
typealias EditRoomAddressScreenViewModelType = StateStoreViewModel<EditRoomAddressScreenViewState, EditRoomAddressScreenViewAction>
|
||||
|
||||
class EditRoomAddressScreenViewModel: EditRoomAddressScreenViewModelType, EditRoomAddressScreenViewModelProtocol {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<EditRoomAddressScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<EditRoomAddressScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
@CancellableTask private var checkAliasAvailabilityTask: Task<Void, Never>?
|
||||
|
||||
init(initialViewState: EditRoomAddressScreenViewState? = nil,
|
||||
roomProxy: JoinedRoomProxyProtocol,
|
||||
clientProxy: ClientProxyProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.roomProxy = roomProxy
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
var aliasLocalPart = ""
|
||||
if let canonicalAlias = roomProxy.infoPublisher.value.canonicalAlias {
|
||||
aliasLocalPart = canonicalAlias.dropFirst().split(separator: ":").first.flatMap(String.init) ?? ""
|
||||
} else if let displayName = roomProxy.infoPublisher.value.displayName {
|
||||
aliasLocalPart = roomAliasNameFromRoomDisplayName(roomName: displayName)
|
||||
}
|
||||
|
||||
if let initialViewState {
|
||||
super.init(initialViewState: initialViewState)
|
||||
} else {
|
||||
super.init(initialViewState: EditRoomAddressScreenViewState(serverName: clientProxy.userIDServerName ?? "",
|
||||
currentAliasLocalPart: aliasLocalPart,
|
||||
bindings: .init(desiredAliasLocalPart: aliasLocalPart)))
|
||||
}
|
||||
setupSubscriptions()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: EditRoomAddressScreenViewAction) {
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .save:
|
||||
Task { await save() }
|
||||
case .cancel:
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
}
|
||||
|
||||
private func setupSubscriptions() {
|
||||
context.$viewState
|
||||
.map(\.bindings.desiredAliasLocalPart)
|
||||
.removeDuplicates()
|
||||
.debounce(for: 0.5, scheduler: DispatchQueue.main)
|
||||
.sink { [weak self] aliasLocalPart in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: aliasLocalPart,
|
||||
serverName: state.serverName) else {
|
||||
// While is empty don't display the errors, since the save button is already disabled
|
||||
state.aliasErrors.removeAll()
|
||||
return
|
||||
}
|
||||
|
||||
if !isRoomAliasFormatValid(alias: canonicalAlias) {
|
||||
state.aliasErrors.insert(.invalidSymbols)
|
||||
// If the alias is invalid we don't need to check for availability
|
||||
state.aliasErrors.remove(.alreadyExists)
|
||||
checkAliasAvailabilityTask = nil
|
||||
return
|
||||
}
|
||||
|
||||
state.aliasErrors.remove(.invalidSymbols)
|
||||
|
||||
guard aliasLocalPart != state.currentAliasLocalPart else {
|
||||
// Doesn't make sense to check the availability and display an error if the alias didn't change, the save button should also be disabled
|
||||
state.aliasErrors.remove(.alreadyExists)
|
||||
checkAliasAvailabilityTask = nil
|
||||
return
|
||||
}
|
||||
|
||||
checkAliasAvailabilityTask = Task { [weak self] in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
if case .success(false) = await self.clientProxy.isAliasAvailable(canonicalAlias) {
|
||||
guard !Task.isCancelled else { return }
|
||||
state.aliasErrors.insert(.alreadyExists)
|
||||
} else {
|
||||
guard !Task.isCancelled else { return }
|
||||
state.aliasErrors.remove(.alreadyExists)
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func save() async {
|
||||
showLoadingIndicator()
|
||||
|
||||
defer {
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
|
||||
guard let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: state.bindings.desiredAliasLocalPart, serverName: state.serverName),
|
||||
isRoomAliasFormatValid(alias: canonicalAlias) else {
|
||||
state.aliasErrors = [.invalidSymbols]
|
||||
return
|
||||
}
|
||||
|
||||
switch await clientProxy.isAliasAvailable(canonicalAlias) {
|
||||
case .success(true):
|
||||
break
|
||||
case .success(false):
|
||||
state.aliasErrors = [.alreadyExists]
|
||||
return
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
let oldAlias = roomProxy.infoPublisher.value.canonicalAlias
|
||||
|
||||
// First publish the new alias
|
||||
if case .failure = await roomProxy.publishRoomAliasInRoomDirectory(canonicalAlias) {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
// Then set it as the main alias
|
||||
if case .failure = await roomProxy.updateCanonicalAlias(canonicalAlias, altAliases: []) {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
// And finally delete the old one
|
||||
if let oldAlias, case .failure = await roomProxy.removeRoomAliasFromRoomDirectory(oldAlias) {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(EditRoomAddressScreenViewModel.self)-Loading"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
|
||||
type: .modal,
|
||||
title: L10n.commonLoading,
|
||||
persistent: true))
|
||||
}
|
||||
|
||||
private func hideLoadingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
|
||||
@MainActor
|
||||
protocol EditRoomAddressScreenViewModelProtocol {
|
||||
var actionsPublisher: AnyPublisher<EditRoomAddressScreenViewModelAction, Never> { get }
|
||||
var context: EditRoomAddressScreenViewModelType.Context { get }
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct EditRoomAddressScreen: View {
|
||||
@ObservedObject var context: EditRoomAddressScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
EditRoomAddressListRow(aliasLocalPart: $context.desiredAliasLocalPart,
|
||||
serverName: context.viewState.serverName, shouldDisplayError: context.viewState.aliasErrors.errorDescription != nil)
|
||||
.onChange(of: context.desiredAliasLocalPart) { _, newAliasLocalPart in
|
||||
context.desiredAliasLocalPart = newAliasLocalPart.lowercased()
|
||||
}
|
||||
.onSubmit {
|
||||
if context.viewState.canSave {
|
||||
context.send(viewAction: .save)
|
||||
}
|
||||
}
|
||||
} footer: {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if let errorDescription = context.viewState.aliasErrors.errorDescription {
|
||||
Label(errorDescription, icon: \.error, iconSize: .xSmall, relativeTo: .compound.bodySM)
|
||||
.foregroundStyle(.compound.textCriticalPrimary)
|
||||
.font(.compound.bodySM)
|
||||
}
|
||||
Text(L10n.screenCreateRoomRoomAddressSectionFooter)
|
||||
.compoundListSectionFooter()
|
||||
.font(.compound.bodySM)
|
||||
}
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(L10n.screenEditRoomAddressTitle)
|
||||
.toolbar { toolbar }
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(L10n.actionSave) {
|
||||
context.send(viewAction: .save)
|
||||
}
|
||||
.disabled(!context.viewState.canSave)
|
||||
}
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(L10n.actionCancel) {
|
||||
context.send(viewAction: .cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct EditRoomAddressScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let noAliasviewModel = EditRoomAddressScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Room Name")),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let aliasviewModel = EditRoomAddressScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Room Name", canonicalAlias: "#room-alias:matrix.org")),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let invalidSymbolsViewModel = EditRoomAddressScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Room Name", canonicalAlias: "#room#-alias:matrix.org")),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let alreadyExistingViewModel = {
|
||||
let clientProxy = ClientProxyMock(.init(userIDServerName: "matrix.org"))
|
||||
clientProxy.isAliasAvailableReturnValue = .success(false)
|
||||
return EditRoomAddressScreenViewModel(initialViewState: .init(serverName: "matrix.org",
|
||||
bindings: .init(desiredAliasLocalPart: "whatever")),
|
||||
roomProxy: JoinedRoomProxyMock(.init(name: "Room Name")),
|
||||
clientProxy: clientProxy,
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: noAliasviewModel.context)
|
||||
}
|
||||
.previewDisplayName("No alias")
|
||||
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: aliasviewModel.context)
|
||||
}
|
||||
.previewDisplayName("With alias")
|
||||
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: invalidSymbolsViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: invalidSymbolsViewModel.context.$viewState.map { state in
|
||||
!state.aliasErrors.isEmpty
|
||||
})
|
||||
.previewDisplayName("Invalid symbols")
|
||||
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: alreadyExistingViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: alreadyExistingViewModel.context.$viewState.map { state in
|
||||
!state.aliasErrors.isEmpty
|
||||
})
|
||||
.previewDisplayName("Already existing")
|
||||
}
|
||||
}
|
||||
+8
-9
@@ -10,16 +10,15 @@ import SwiftUI
|
||||
|
||||
struct SecurityAndPrivacyScreenCoordinatorParameters {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyScreenCoordinatorAction {
|
||||
case done
|
||||
|
||||
// Consider adding CustomStringConvertible conformance if the actions contain PII
|
||||
case displayEditAddressScreen
|
||||
}
|
||||
|
||||
final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
private let parameters: SecurityAndPrivacyScreenCoordinatorParameters
|
||||
private let viewModel: SecurityAndPrivacyScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
@@ -30,9 +29,9 @@ final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
}
|
||||
|
||||
init(parameters: SecurityAndPrivacyScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: parameters.roomProxy)
|
||||
viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
clientProxy: parameters.clientProxy,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
@@ -41,8 +40,8 @@ final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .done:
|
||||
actionsSubject.send(.done)
|
||||
case .displayEditAddressScreen:
|
||||
actionsSubject.send(.displayEditAddressScreen)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
+49
-7
@@ -8,21 +8,44 @@
|
||||
import Foundation
|
||||
|
||||
enum SecurityAndPrivacyScreenViewModelAction {
|
||||
case done
|
||||
case displayEditAddressScreen
|
||||
}
|
||||
|
||||
struct SecurityAndPrivacyScreenViewState: BindableState {
|
||||
var bindings: SecurityAndPrivacyScreenViewStateBindings
|
||||
|
||||
let serverName: String
|
||||
var currentSettings: SecurityAndPrivacySettings
|
||||
var bindings: SecurityAndPrivacyScreenViewStateBindings
|
||||
var canonicalAlias: String?
|
||||
|
||||
var hasChanges: Bool {
|
||||
private var hasChanges: Bool {
|
||||
currentSettings != bindings.desiredSettings
|
||||
}
|
||||
|
||||
init(accessType: SecurityAndPrivacyRoomAccessType,
|
||||
isEncryptionEnabled: Bool) {
|
||||
let settings = SecurityAndPrivacySettings(accessType: accessType, isEncryptionEnabled: isEncryptionEnabled)
|
||||
var isSaveDisabled: Bool {
|
||||
!hasChanges ||
|
||||
(currentSettings.isVisibileInRoomDirectory == nil &&
|
||||
bindings.desiredSettings.accessType != .inviteOnly &&
|
||||
canonicalAlias != nil)
|
||||
}
|
||||
|
||||
var availableVisibilityOptions: [SecurityAndPrivacyHistoryVisibility] {
|
||||
var options = [SecurityAndPrivacyHistoryVisibility.sinceSelection]
|
||||
if !bindings.desiredSettings.isEncryptionEnabled, bindings.desiredSettings.accessType == .anyone {
|
||||
options.append(.anyone)
|
||||
} else {
|
||||
options.append(.sinceInvite)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
init(serverName: String,
|
||||
accessType: SecurityAndPrivacyRoomAccessType,
|
||||
isEncryptionEnabled: Bool,
|
||||
historyVisibility: SecurityAndPrivacyHistoryVisibility) {
|
||||
self.serverName = serverName
|
||||
let settings = SecurityAndPrivacySettings(accessType: accessType,
|
||||
isEncryptionEnabled: isEncryptionEnabled,
|
||||
historyVisibility: historyVisibility)
|
||||
currentSettings = settings
|
||||
bindings = SecurityAndPrivacyScreenViewStateBindings(desiredSettings: settings)
|
||||
}
|
||||
@@ -36,12 +59,15 @@ struct SecurityAndPrivacyScreenViewStateBindings {
|
||||
struct SecurityAndPrivacySettings: Equatable {
|
||||
var accessType: SecurityAndPrivacyRoomAccessType
|
||||
var isEncryptionEnabled: Bool
|
||||
var historyVisibility: SecurityAndPrivacyHistoryVisibility
|
||||
var isVisibileInRoomDirectory: Bool?
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyRoomAccessType {
|
||||
case inviteOnly
|
||||
case askToJoin
|
||||
case anyone
|
||||
case spaceUsers
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyAlertType {
|
||||
@@ -51,4 +77,20 @@ enum SecurityAndPrivacyAlertType {
|
||||
enum SecurityAndPrivacyScreenViewAction {
|
||||
case save
|
||||
case tryUpdatingEncryption(Bool)
|
||||
case editAddress
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyHistoryVisibility {
|
||||
case sinceSelection
|
||||
case sinceInvite
|
||||
case anyone
|
||||
|
||||
var fallbackOption: Self {
|
||||
switch self {
|
||||
case .sinceInvite, .sinceSelection:
|
||||
return .sinceSelection
|
||||
case .anyone:
|
||||
return .sinceInvite
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+176
-12
@@ -6,22 +6,34 @@
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
typealias SecurityAndPrivacyScreenViewModelType = StateStoreViewModel<SecurityAndPrivacyScreenViewState, SecurityAndPrivacyScreenViewAction>
|
||||
|
||||
class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType, SecurityAndPrivacyScreenViewModelProtocol {
|
||||
private let roomProxy: JoinedRoomProxyProtocol
|
||||
private let clientProxy: ClientProxyProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SecurityAndPrivacyScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SecurityAndPrivacyScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(roomProxy: JoinedRoomProxyProtocol) {
|
||||
|
||||
init(roomProxy: JoinedRoomProxyProtocol,
|
||||
clientProxy: ClientProxyProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.roomProxy = roomProxy
|
||||
super.init(initialViewState: SecurityAndPrivacyScreenViewState(accessType: roomProxy.infoPublisher.value.roomAccessType,
|
||||
isEncryptionEnabled: roomProxy.isEncrypted))
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
super.init(initialViewState: SecurityAndPrivacyScreenViewState(serverName: clientProxy.userIDServerName ?? "",
|
||||
accessType: roomProxy.infoPublisher.value.joinRule.toSecurityAndPrivacyRoomAccessType,
|
||||
isEncryptionEnabled: roomProxy.isEncrypted,
|
||||
historyVisibility: roomProxy.infoPublisher.value.historyVisibility.toSecurityAndPrivacyHistoryVisibility))
|
||||
|
||||
setupRoomDirectoryVisibility()
|
||||
setupSubscriptions()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -31,32 +43,184 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
|
||||
switch viewAction {
|
||||
case .save:
|
||||
actionsSubject.send(.done)
|
||||
Task {
|
||||
await saveDesiredSettings()
|
||||
}
|
||||
case .tryUpdatingEncryption(let updatedValue):
|
||||
if updatedValue {
|
||||
state.bindings.alertInfo = .init(id: .enableEncryption,
|
||||
title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertTitle,
|
||||
message: L10n.screenSecurityAndPrivacyEnableEncryptionAlertDescription,
|
||||
primaryButton: .init(title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertConfirmButtonTitle) { [weak self] in
|
||||
self?.state.bindings.desiredSettings.isEncryptionEnabled = true
|
||||
},
|
||||
primaryButton: .init(title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertConfirmButtonTitle) { [weak self] in self?.state.bindings.desiredSettings.isEncryptionEnabled = true },
|
||||
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil))
|
||||
} else {
|
||||
state.bindings.desiredSettings.isEncryptionEnabled = false
|
||||
}
|
||||
case .editAddress:
|
||||
actionsSubject.send(.displayEditAddressScreen)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func setupSubscriptions() {
|
||||
context.$viewState
|
||||
.map(\.availableVisibilityOptions)
|
||||
.removeDuplicates()
|
||||
// To allow the view to update properly
|
||||
.receive(on: DispatchQueue.main)
|
||||
// When the available options changes always default to `sinceSelection` if the currently selected option is not available
|
||||
.sink { [weak self] availableVisibilityOptions in
|
||||
guard let self else { return }
|
||||
let desiredHistoryVisibility = state.bindings.desiredSettings.historyVisibility
|
||||
if !availableVisibilityOptions.contains(desiredHistoryVisibility) {
|
||||
state.bindings.desiredSettings.historyVisibility = desiredHistoryVisibility.fallbackOption
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
roomProxy.infoPublisher
|
||||
.map(\.canonicalAlias)
|
||||
.removeDuplicates()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.canonicalAlias, on: self)
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func setupRoomDirectoryVisibility() {
|
||||
Task {
|
||||
switch await roomProxy.isVisibleInRoomDirectory() {
|
||||
case .success(let value):
|
||||
state.bindings.desiredSettings.isVisibileInRoomDirectory = value
|
||||
state.currentSettings.isVisibileInRoomDirectory = value
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
state.bindings.desiredSettings.isVisibileInRoomDirectory = false
|
||||
state.currentSettings.isVisibileInRoomDirectory = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func saveDesiredSettings() async {
|
||||
showLoadingIndicator()
|
||||
|
||||
defer {
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
|
||||
if state.currentSettings.isEncryptionEnabled != state.bindings.desiredSettings.isEncryptionEnabled {
|
||||
switch await roomProxy.enableEncryption() {
|
||||
case .success:
|
||||
state.currentSettings.isEncryptionEnabled = state.bindings.desiredSettings.isEncryptionEnabled
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
if state.currentSettings.historyVisibility != state.bindings.desiredSettings.historyVisibility {
|
||||
switch await roomProxy.updateHistoryVisibility(state.bindings.desiredSettings.historyVisibility.toRoomHistoryVisibility) {
|
||||
case .success:
|
||||
state.currentSettings.historyVisibility = state.bindings.desiredSettings.historyVisibility
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
if state.currentSettings.accessType != state.bindings.desiredSettings.accessType {
|
||||
// When a user changes join rules to something other than knock or public,
|
||||
// the room should be automatically made invisible (private) in the room directory.
|
||||
if state.currentSettings.accessType != .askToJoin, state.currentSettings.accessType != .anyone {
|
||||
state.bindings.desiredSettings.isVisibileInRoomDirectory = false
|
||||
}
|
||||
|
||||
switch await roomProxy.updateJoinRule(state.bindings.desiredSettings.accessType.toJoinRule) {
|
||||
case .success:
|
||||
state.currentSettings.accessType = state.bindings.desiredSettings.accessType
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
if state.currentSettings.isVisibileInRoomDirectory != state.bindings.desiredSettings.isVisibileInRoomDirectory {
|
||||
let visibility: RoomVisibility = state.bindings.desiredSettings.isVisibileInRoomDirectory == true ? .public : .private
|
||||
|
||||
switch await roomProxy.updateRoomDirectoryVisibility(visibility) {
|
||||
case .success:
|
||||
state.currentSettings.isVisibileInRoomDirectory = state.bindings.desiredSettings.isVisibileInRoomDirectory
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(EditRoomAddressScreenViewModel.self)-Loading"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
|
||||
type: .modal,
|
||||
title: L10n.commonLoading,
|
||||
persistent: true))
|
||||
}
|
||||
|
||||
private func hideLoadingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
private extension SecurityAndPrivacyRoomAccessType {
|
||||
var toJoinRule: JoinRule {
|
||||
switch self {
|
||||
case .inviteOnly:
|
||||
.invite
|
||||
case .askToJoin:
|
||||
.knock
|
||||
case .anyone:
|
||||
.public
|
||||
case .spaceUsers:
|
||||
fatalError("The user shouldn't be able to select this rule")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomInfoProxy {
|
||||
var roomAccessType: SecurityAndPrivacyRoomAccessType {
|
||||
switch joinRule {
|
||||
case .invite, .restricted:
|
||||
private extension Optional where Wrapped == JoinRule {
|
||||
var toSecurityAndPrivacyRoomAccessType: SecurityAndPrivacyRoomAccessType {
|
||||
switch self {
|
||||
case .none, .public:
|
||||
return .anyone
|
||||
case .invite:
|
||||
return .inviteOnly
|
||||
case .knock, .knockRestricted:
|
||||
return .askToJoin
|
||||
case .restricted:
|
||||
return .spaceUsers
|
||||
default:
|
||||
return .inviteOnly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomHistoryVisibility {
|
||||
var toSecurityAndPrivacyHistoryVisibility: SecurityAndPrivacyHistoryVisibility {
|
||||
switch self {
|
||||
case .joined, .invited:
|
||||
return .sinceInvite
|
||||
case .shared, .custom:
|
||||
return .sinceSelection
|
||||
case .worldReadable:
|
||||
return .anyone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension SecurityAndPrivacyHistoryVisibility {
|
||||
var toRoomHistoryVisibility: RoomHistoryVisibility {
|
||||
switch self {
|
||||
case .sinceSelection:
|
||||
return .shared
|
||||
case .sinceInvite:
|
||||
return .invited
|
||||
case .anyone:
|
||||
return .worldReadable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+153
-7
@@ -14,7 +14,18 @@ struct SecurityAndPrivacyScreen: View {
|
||||
var body: some View {
|
||||
Form {
|
||||
roomAccessSection
|
||||
if context.desiredSettings.accessType != .inviteOnly {
|
||||
if let canonicalAlias = context.viewState.canonicalAlias {
|
||||
visibilitySection
|
||||
addressSection(canonicalAlias: canonicalAlias)
|
||||
roomDirectoryVisibilitySection
|
||||
} else {
|
||||
publishingSection
|
||||
addAddressSection
|
||||
}
|
||||
}
|
||||
encryptionSection
|
||||
historySection
|
||||
}
|
||||
.compoundList()
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
@@ -34,6 +45,14 @@ struct SecurityAndPrivacyScreen: View {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomAccessAnyoneOptionTitle,
|
||||
description: L10n.screenSecurityAndPrivacyRoomAccessAnyoneOptionDescription),
|
||||
kind: .selection(isSelected: context.desiredSettings.accessType == .anyone) { context.desiredSettings.accessType = .anyone })
|
||||
|
||||
if context.viewState.currentSettings.accessType == .spaceUsers {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomAccessSpaceMembersOptionTitle,
|
||||
description: L10n.screenSecurityAndPrivacyRoomAccessSpaceMembersOptionDescription),
|
||||
kind: .selection(isSelected: context.desiredSettings.accessType == .spaceUsers) { })
|
||||
// This is not supported so it will always be disabled and has no handler
|
||||
.disabled(true)
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomAccessSectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
@@ -42,7 +61,7 @@ struct SecurityAndPrivacyScreen: View {
|
||||
|
||||
@ViewBuilder
|
||||
private var encryptionSection: some View {
|
||||
let encryptionBinding = Binding<Bool>(get: {
|
||||
let binding = Binding<Bool>(get: {
|
||||
context.desiredSettings.isEncryptionEnabled
|
||||
}, set: { newValue in
|
||||
context.send(viewAction: .tryUpdatingEncryption(newValue))
|
||||
@@ -50,7 +69,7 @@ struct SecurityAndPrivacyScreen: View {
|
||||
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyEncryptionToggleTitle),
|
||||
kind: .toggle(encryptionBinding))
|
||||
kind: .toggle(binding))
|
||||
// We don't allow editing the encryption state if the current setting on the server is `enabled`
|
||||
.disabled(context.viewState.currentSettings.isEncryptionEnabled)
|
||||
} header: {
|
||||
@@ -62,26 +81,153 @@ struct SecurityAndPrivacyScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var historySection: some View {
|
||||
Section {
|
||||
ForEach(context.viewState.availableVisibilityOptions, id: \.self) { option in
|
||||
switch option {
|
||||
case .sinceSelection:
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomHistorySinceSelectingOptionTitle),
|
||||
kind: .selection(isSelected: context.desiredSettings.historyVisibility == .sinceSelection) { context.desiredSettings.historyVisibility = .sinceSelection })
|
||||
case .anyone:
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomHistoryAnyoneOptionTitle),
|
||||
kind: .selection(isSelected: context.desiredSettings.historyVisibility == .anyone) { context.desiredSettings.historyVisibility = .anyone })
|
||||
case .sinceInvite:
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomHistorySinceInviteOptionTitle),
|
||||
kind: .selection(isSelected: context.desiredSettings.historyVisibility == .sinceInvite) { context.desiredSettings.historyVisibility = .sinceInvite })
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomHistorySectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
}
|
||||
|
||||
private var visibilitySection: some View {
|
||||
Section {
|
||||
EmptyView()
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomVisibilitySectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomVisibilitySectionFooter(context.viewState.serverName))
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
private func addressSection(canonicalAlias: String) -> some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: canonicalAlias), kind: .navigationLink { context.send(viewAction: .editAddress) })
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomAddressSectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomAddressSectionFooter)
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
private var publishingSection: some View {
|
||||
Section {
|
||||
EmptyView()
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomPublishingSectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomPublishingSectionFooter)
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
private var addAddressSection: some View {
|
||||
Section {
|
||||
ListRow(kind: .custom {
|
||||
Button(L10n.screenSecurityAndPrivacyAddRoomAddressAction) { context.send(viewAction: .editAddress) }
|
||||
.foregroundColor(.compound.textActionAccent)
|
||||
.padding(ListRowPadding.insets)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var roomDirectoryVisibilitySection: some View {
|
||||
let binding = Binding<Bool>(get: {
|
||||
context.desiredSettings.isVisibileInRoomDirectory ?? false
|
||||
}, set: { newValue in
|
||||
context.desiredSettings.isVisibileInRoomDirectory = newValue
|
||||
})
|
||||
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomDirectoryVisibilityToggleTitle),
|
||||
details: .isWaiting(context.desiredSettings.isVisibileInRoomDirectory == nil),
|
||||
kind: context.desiredSettings.isVisibileInRoomDirectory == nil ? .label : .toggle(binding))
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomDirectoryVisibilitySectionFooter(context.viewState.serverName))
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
var toolbar: some ToolbarContent {
|
||||
private var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(L10n.actionSave) {
|
||||
context.send(viewAction: .save)
|
||||
}
|
||||
.disabled(!context.viewState.hasChanges)
|
||||
.disabled(context.viewState.isSaveDisabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
// TODO: Add back TestablePreview, this is WIP so running preview tests for it is not necessary
|
||||
struct SecurityAndPrivacyScreen_Previews: PreviewProvider {
|
||||
static let inviteOnlyViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(joinRule: .invite)))
|
||||
struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let inviteOnlyViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(joinRule: .invite)),
|
||||
clientProxy: ClientProxyMock(.init()),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let publicViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false,
|
||||
canonicalAlias: "#room:matrix.org",
|
||||
joinRule: .public,
|
||||
isVisibleInPublicDirectory: true)),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let publicNoAddressViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false,
|
||||
joinRule: .public)),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let restrictedViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false,
|
||||
canonicalAlias: "#room:matrix.org",
|
||||
joinRule: .restricted(rules: []),
|
||||
isVisibleInPublicDirectory: true)),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: inviteOnlyViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Private invite only room")
|
||||
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: publicViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: publicViewModel.context.$viewState.map { state in
|
||||
state.currentSettings.isVisibileInRoomDirectory == true
|
||||
})
|
||||
.previewDisplayName("Public room")
|
||||
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: publicNoAddressViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Public room without address")
|
||||
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: restrictedViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: restrictedViewModel.context.$viewState.map { state in
|
||||
state.currentSettings.isVisibileInRoomDirectory == true
|
||||
})
|
||||
.previewDisplayName("Restricted room")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user