generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added the security and settings button in details * added content to the view * added enable encryption alert * updated preview tests and the UI * removed wrong plists committed by mistake * pr suggestions
- Loading branch information
Showing
20 changed files
with
398 additions
and
16 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// 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 SwiftUI | ||
|
||
struct SecurityAndPrivacyScreenCoordinatorParameters { | ||
let roomProxy: JoinedRoomProxyProtocol | ||
} | ||
|
||
enum SecurityAndPrivacyScreenCoordinatorAction { | ||
case done | ||
|
||
// Consider adding CustomStringConvertible conformance if the actions contain PII | ||
} | ||
|
||
final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol { | ||
private let parameters: SecurityAndPrivacyScreenCoordinatorParameters | ||
private let viewModel: SecurityAndPrivacyScreenViewModelProtocol | ||
|
||
private var cancellables = Set<AnyCancellable>() | ||
|
||
private let actionsSubject: PassthroughSubject<SecurityAndPrivacyScreenCoordinatorAction, Never> = .init() | ||
var actionsPublisher: AnyPublisher<SecurityAndPrivacyScreenCoordinatorAction, Never> { | ||
actionsSubject.eraseToAnyPublisher() | ||
} | ||
|
||
init(parameters: SecurityAndPrivacyScreenCoordinatorParameters) { | ||
self.parameters = parameters | ||
|
||
viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: parameters.roomProxy) | ||
} | ||
|
||
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 .done: | ||
actionsSubject.send(.done) | ||
} | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
func toPresentable() -> AnyView { | ||
AnyView(SecurityAndPrivacyScreen(context: viewModel.context)) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenModels.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// 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 SecurityAndPrivacyScreenViewModelAction { | ||
case done | ||
} | ||
|
||
struct SecurityAndPrivacyScreenViewState: BindableState { | ||
var bindings: SecurityAndPrivacyScreenViewStateBindings | ||
|
||
var currentSettings: SecurityAndPrivacySettings | ||
|
||
var hasChanges: Bool { | ||
currentSettings != bindings.desiredSettings | ||
} | ||
|
||
init(accessType: SecurityAndPrivacyRoomAccessType, | ||
isEncryptionEnabled: Bool) { | ||
let settings = SecurityAndPrivacySettings(accessType: accessType, isEncryptionEnabled: isEncryptionEnabled) | ||
currentSettings = settings | ||
bindings = SecurityAndPrivacyScreenViewStateBindings(desiredSettings: settings) | ||
} | ||
} | ||
|
||
struct SecurityAndPrivacyScreenViewStateBindings { | ||
var desiredSettings: SecurityAndPrivacySettings | ||
var alertInfo: AlertInfo<SecurityAndPrivacyAlertType>? | ||
} | ||
|
||
struct SecurityAndPrivacySettings: Equatable { | ||
var accessType: SecurityAndPrivacyRoomAccessType | ||
var isEncryptionEnabled: Bool | ||
} | ||
|
||
enum SecurityAndPrivacyRoomAccessType { | ||
case inviteOnly | ||
case askToJoin | ||
case anyone | ||
} | ||
|
||
enum SecurityAndPrivacyAlertType { | ||
case enableEncryption | ||
} | ||
|
||
enum SecurityAndPrivacyScreenViewAction { | ||
case save | ||
case tryUpdatingEncryption(Bool) | ||
} |
61 changes: 61 additions & 0 deletions
61
ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// 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 SwiftUI | ||
|
||
typealias SecurityAndPrivacyScreenViewModelType = StateStoreViewModel<SecurityAndPrivacyScreenViewState, SecurityAndPrivacyScreenViewAction> | ||
|
||
class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType, SecurityAndPrivacyScreenViewModelProtocol { | ||
private let roomProxy: JoinedRoomProxyProtocol | ||
|
||
private let actionsSubject: PassthroughSubject<SecurityAndPrivacyScreenViewModelAction, Never> = .init() | ||
var actionsPublisher: AnyPublisher<SecurityAndPrivacyScreenViewModelAction, Never> { | ||
actionsSubject.eraseToAnyPublisher() | ||
} | ||
|
||
init(roomProxy: JoinedRoomProxyProtocol) { | ||
self.roomProxy = roomProxy | ||
super.init(initialViewState: SecurityAndPrivacyScreenViewState(accessType: roomProxy.infoPublisher.value.roomAccessType, | ||
isEncryptionEnabled: roomProxy.isEncrypted)) | ||
} | ||
|
||
// MARK: - Public | ||
|
||
override func process(viewAction: SecurityAndPrivacyScreenViewAction) { | ||
MXLog.info("View model: received view action: \(viewAction)") | ||
|
||
switch viewAction { | ||
case .save: | ||
actionsSubject.send(.done) | ||
case .tryUpdatingEncryption(let updatedValue): | ||
if updatedValue { | ||
state.bindings.alertInfo = .init(id: .enableEncryption, | ||
title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertTitle, | ||
message: L10n.screenSecurityAndPrivacyEnableEncryptionAlertDescription, | ||
primaryButton: .init(title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertConfirmButtonTitle, | ||
action: { [weak self] in self?.state.bindings.desiredSettings.isEncryptionEnabled = true }), | ||
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil)) | ||
} else { | ||
state.bindings.desiredSettings.isEncryptionEnabled = false | ||
} | ||
} | ||
} | ||
} | ||
|
||
private extension RoomInfoProxy { | ||
var roomAccessType: SecurityAndPrivacyRoomAccessType { | ||
switch joinRule { | ||
case .invite, .restricted: | ||
return .inviteOnly | ||
case .knock, .knockRestricted: | ||
return .askToJoin | ||
default: | ||
return .anyone | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenViewModelProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 SecurityAndPrivacyScreenViewModelProtocol { | ||
var actionsPublisher: AnyPublisher<SecurityAndPrivacyScreenViewModelAction, Never> { get } | ||
var context: SecurityAndPrivacyScreenViewModelType.Context { get } | ||
} |
Oops, something went wrong.