Key backup returns (#1951)

* Converge on UserSessionFlowCoordinator logout confirmation

* Add logout confirmation screen strings to untranslated.

* Fix chat backup learn more URl fragment.

* Implement logout flows that check recovery and key backup for the last session

* Move logout confirmation screen strings to localazy

* Change encrypted timeline item copy to "Waiting for decryption key"

* Use different encrypted history banner based on key backup states

* Introduce a SettingsFlowCoordinator and implement navigation directly to the secure backup screen from the logout flows.

* Fix **mocked** secure backup controller flows

* Simplify encrypted history banner logic

* Address PR comments
This commit is contained in:
Stefan Ceriu
2023-10-24 18:38:41 +03:00
committed by GitHub
parent 6e5680fc36
commit 37f1a79a11
34 changed files with 806 additions and 111 deletions
@@ -34,7 +34,7 @@ enum HomeScreenCoordinatorAction {
case presentSessionVerificationScreen
case presentStartChatScreen
case presentInvitesScreen
case signOut
case logout
}
final class HomeScreenCoordinator: CoordinatorProtocol {
@@ -75,8 +75,8 @@ final class HomeScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.presentSettingsScreen)
case .presentSessionVerificationScreen:
actionsSubject.send(.presentSessionVerificationScreen)
case .signOut:
actionsSubject.send(.signOut)
case .logout:
actionsSubject.send(.logout)
case .presentStartChatScreen:
actionsSubject.send(.presentStartChatScreen)
case .presentInvitesScreen:
@@ -27,13 +27,13 @@ enum HomeScreenViewModelAction {
case presentFeedbackScreen
case presentStartChatScreen
case presentInvitesScreen
case signOut
case logout
}
enum HomeScreenViewUserMenuAction {
case settings
case feedback
case signOut
case logout
}
enum HomeScreenViewAction {
@@ -138,8 +138,8 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
actionsSubject.send(.presentFeedbackScreen)
case .settings:
actionsSubject.send(.presentSettingsScreen)
case .signOut:
actionsSubject.send(.signOut)
case .logout:
actionsSubject.send(.logout)
}
case .verifySession:
actionsSubject.send(.presentSessionVerificationScreen)
@@ -18,7 +18,6 @@ import Compound
import SwiftUI
struct HomeScreenUserMenuButton: View {
@State private var showingLogoutConfirmation = false
@Environment(\.colorScheme) var colorScheme
@ObservedObject var context: HomeScreenViewModel.Context
@@ -53,7 +52,7 @@ struct HomeScreenUserMenuButton: View {
}
Section {
Button(role: .destructive) {
showingLogoutConfirmation = true
context.send(viewAction: .userMenu(action: .logout))
} label: {
Label(L10n.screenSignoutPreferenceItem, systemImage: "rectangle.portrait.and.arrow.right")
}
@@ -68,15 +67,6 @@ struct HomeScreenUserMenuButton: View {
.overlayBadge(10, isBadged: context.viewState.showUserMenuBadge)
.compositingGroup()
}
.alert(L10n.screenSignoutConfirmationDialogTitle,
isPresented: $showingLogoutConfirmation) {
Button(L10n.screenSignoutConfirmationDialogSubmit,
role: .destructive) {
context.send(viewAction: .userMenu(action: .signOut))
}
} message: {
Text(L10n.screenSignoutConfirmationDialogContent)
}
.accessibilityLabel(L10n.a11yUserMenu)
}
}
@@ -24,7 +24,7 @@ struct EncryptedHistoryRoomTimelineView: View {
var body: some View {
Label {
Text(L10n.screenRoomEncryptedHistoryBanner)
Text(title)
.font(.compound.bodyMDSemibold)
.foregroundColor(.compound.textInfoPrimary)
} icon: {
@@ -43,6 +43,10 @@ struct EncryptedHistoryRoomTimelineView: View {
.padding(.horizontal, 8)
.padding(.vertical, 16)
}
private var title: String {
timelineItem.isSessionVerified ? L10n.screenRoomEncryptedHistoryBanner : L10n.screenRoomEncryptedHistoryBannerUnverified
}
}
private struct EncryptedHistoryLabelStyle: LabelStyle {
@@ -56,7 +60,9 @@ private struct EncryptedHistoryLabelStyle: LabelStyle {
struct EncryptedHistoryRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
let item = EncryptedHistoryRoomTimelineItem(id: .random)
EncryptedHistoryRoomTimelineView(timelineItem: item)
VStack {
EncryptedHistoryRoomTimelineView(timelineItem: .init(id: .random, isSessionVerified: true))
EncryptedHistoryRoomTimelineView(timelineItem: .init(id: .random, isSessionVerified: false))
}
}
}
@@ -21,8 +21,6 @@ import SwiftUI
struct SecureBackupKeyBackupScreen: View {
@ObservedObject var context: SecureBackupKeyBackupScreenViewModel.Context
@ScaledMetric private var iconSize = 70
var body: some View {
mainContent
.padding()
@@ -0,0 +1,69 @@
//
// Copyright 2022 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 Combine
import SwiftUI
struct SecureBackupLogoutConfirmationScreenCoordinatorParameters {
let secureBackupController: SecureBackupControllerProtocol
let networkMonitor: NetworkMonitorProtocol
}
enum SecureBackupLogoutConfirmationScreenCoordinatorAction {
case cancel
case settings
case logout
}
final class SecureBackupLogoutConfirmationScreenCoordinator: CoordinatorProtocol {
private let parameters: SecureBackupLogoutConfirmationScreenCoordinatorParameters
private var viewModel: SecureBackupLogoutConfirmationScreenViewModelProtocol
private let actionsSubject: PassthroughSubject<SecureBackupLogoutConfirmationScreenCoordinatorAction, Never> = .init()
private var cancellables = Set<AnyCancellable>()
var actions: AnyPublisher<SecureBackupLogoutConfirmationScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: SecureBackupLogoutConfirmationScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = SecureBackupLogoutConfirmationScreenViewModel(secureBackupController: parameters.secureBackupController,
networkMonitor: parameters.networkMonitor)
}
func start() {
viewModel.actions.sink { [weak self] action in
guard let self else { return }
MXLog.info("Coordinator: received view model action: \(action)")
switch action {
case .cancel:
actionsSubject.send(.cancel)
case .settings:
actionsSubject.send(.settings)
case .logout:
actionsSubject.send(.logout)
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(SecureBackupLogoutConfirmationScreen(context: viewModel.context))
}
}
@@ -0,0 +1,39 @@
//
// Copyright 2022 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
enum SecureBackupLogoutConfirmationScreenViewModelAction {
case cancel
case settings
case logout
}
enum SecureBackupLogoutConfirmationScreenViewMode {
case saveRecoveryKey
case backupOngoing
case offline
}
struct SecureBackupLogoutConfirmationScreenViewState: BindableState {
var mode: SecureBackupLogoutConfirmationScreenViewMode
}
enum SecureBackupLogoutConfirmationScreenViewAction {
case cancel
case settings
case logout
}
@@ -0,0 +1,90 @@
//
// Copyright 2022 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 Combine
import SwiftUI
typealias SecureBackupLogoutConfirmationScreenViewModelType = StateStoreViewModel<SecureBackupLogoutConfirmationScreenViewState, SecureBackupLogoutConfirmationScreenViewAction>
class SecureBackupLogoutConfirmationScreenViewModel: SecureBackupLogoutConfirmationScreenViewModelType, SecureBackupLogoutConfirmationScreenViewModelProtocol {
private let secureBackupController: SecureBackupControllerProtocol
private let networkMonitor: NetworkMonitorProtocol
@CancellableTask
private var keyUploadWaitingTask: Task<Void, Never>?
private var actionsSubject: PassthroughSubject<SecureBackupLogoutConfirmationScreenViewModelAction, Never> = .init()
var actions: AnyPublisher<SecureBackupLogoutConfirmationScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(secureBackupController: SecureBackupControllerProtocol, networkMonitor: NetworkMonitorProtocol) {
self.secureBackupController = secureBackupController
self.networkMonitor = networkMonitor
super.init(initialViewState: .init(mode: .saveRecoveryKey))
networkMonitor.reachabilityPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] reachability in
guard let self,
state.mode != .saveRecoveryKey else {
return
}
if reachability == .reachable {
state.mode = .backupOngoing
} else {
state.mode = .offline
}
}
.store(in: &cancellables)
}
// MARK: - Public
override func process(viewAction: SecureBackupLogoutConfirmationScreenViewAction) {
MXLog.info("View model: received view action: \(viewAction)")
switch viewAction {
case .cancel:
keyUploadWaitingTask = nil
actionsSubject.send(.cancel)
case .settings:
actionsSubject.send(.settings)
case .logout:
attemptLogout()
}
}
// MARK: - Private
private func attemptLogout() {
if state.mode == .saveRecoveryKey {
state.mode = networkMonitor.reachabilityPublisher.value == .reachable ? .backupOngoing : .offline
keyUploadWaitingTask = Task {
await secureBackupController.waitForKeyBackup()
guard !Task.isCancelled else { return }
actionsSubject.send(.logout)
}
} else {
actionsSubject.send(.logout)
}
}
}
@@ -0,0 +1,23 @@
//
// Copyright 2022 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 Combine
@MainActor
protocol SecureBackupLogoutConfirmationScreenViewModelProtocol {
var actions: AnyPublisher<SecureBackupLogoutConfirmationScreenViewModelAction, Never> { get }
var context: SecureBackupLogoutConfirmationScreenViewModelType.Context { get }
}
@@ -0,0 +1,134 @@
//
// Copyright 2022 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 Combine
import Compound
import SwiftUI
struct SecureBackupLogoutConfirmationScreen: View {
@ObservedObject var context: SecureBackupLogoutConfirmationScreenViewModel.Context
var body: some View {
NavigationStack {
ScrollView {
VStack(spacing: 16) {
header
content
}
.padding()
}
.toolbar { toolbar }
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
.safeAreaInset(edge: .bottom) { footer.padding() }
}
}
@ViewBuilder
private var header: some View {
HeroImage(image: Image(asset: Asset.Images.secureBackupOff))
}
@ViewBuilder
private var content: some View {
Text(title)
.foregroundColor(.compound.textPrimary)
.font(.compound.headingMDBold)
.multilineTextAlignment(.center)
Text(subtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodyMD)
.multilineTextAlignment(.center)
if context.viewState.mode == .backupOngoing {
Spacer()
ProgressView()
}
}
@ViewBuilder
private var footer: some View {
if context.viewState.mode == .saveRecoveryKey {
Button {
context.send(viewAction: .settings)
} label: {
Text(L10n.commonSettings)
}
.buttonStyle(.compound(.primary))
}
Button(role: .destructive) {
context.send(viewAction: .logout)
} label: {
Text(L10n.actionSignout)
}
.buttonStyle(.compound(.primary))
}
@ToolbarContentBuilder
private var toolbar: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button(L10n.actionCancel) {
context.send(viewAction: .cancel)
}
}
}
var title: String {
switch context.viewState.mode {
case .saveRecoveryKey:
return L10n.screenSignoutSaveRecoveryKeyTitle
case .backupOngoing:
return L10n.screenSignoutKeyBackupOngoingTitle
case .offline:
return L10n.screenSignoutKeyBackupOfflineTitle
}
}
var subtitle: String {
switch context.viewState.mode {
case .saveRecoveryKey:
return L10n.screenSignoutSaveRecoveryKeySubtitle
case .backupOngoing:
return L10n.screenSignoutKeyBackupOngoingSubtitle
case .offline:
return L10n.screenSignoutKeyBackupOfflineSubtitle
}
}
}
// MARK: - Previews
struct SecureBackupLogoutConfirmationScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = buildViewModel()
static var previews: some View {
NavigationStack {
SecureBackupLogoutConfirmationScreen(context: viewModel.context)
}
}
static func buildViewModel() -> SecureBackupLogoutConfirmationScreenViewModelType {
let secureBackupController = SecureBackupControllerMock()
secureBackupController.underlyingKeyBackupState = CurrentValueSubject<SecureBackupKeyBackupState, Never>(.enabled).asCurrentValuePublisher()
let networkMonitor = NetworkMonitorMock()
networkMonitor.underlyingReachabilityPublisher = CurrentValueSubject<NetworkMonitorReachability, Never>(.reachable).asCurrentValuePublisher()
return SecureBackupLogoutConfirmationScreenViewModel(secureBackupController: secureBackupController,
networkMonitor: networkMonitor)
}
}
@@ -21,8 +21,6 @@ import SwiftUI
struct SecureBackupRecoveryKeyScreen: View {
@ObservedObject var context: SecureBackupRecoveryKeyScreenViewModel.Context
@ScaledMetric private var iconSize = 70
var body: some View {
mainContent
.padding()
@@ -32,6 +32,7 @@ enum SettingsScreenCoordinatorAction {
case dismiss
case logout
case clearCache
case secureBackup
}
final class SettingsScreenCoordinator: CoordinatorProtocol {
@@ -75,7 +76,7 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
case .sessionVerification:
presentSessionVerificationScreen()
case .secureBackup:
presentSecureBackupScreen()
actionsSubject.send(.secureBackup)
case .accountSessionsList:
presentAccountSessionsListURL()
case .notifications:
@@ -200,15 +201,6 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
}
}
private func presentSecureBackupScreen() {
let coordinator = SecureBackupScreenCoordinator(parameters: .init(appSettings: parameters.appSettings,
secureBackupController: parameters.userSession.clientProxy.secureBackupController,
navigationStackCoordinator: parameters.navigationStackCoordinator,
userIndicatorController: parameters.userIndicatorController))
parameters.navigationStackCoordinator?.push(coordinator)
}
private func presentNotificationSettings() {
let notificationParameters = NotificationSettingsScreenCoordinatorParameters(navigationStackCoordinator: parameters.navigationStackCoordinator,
userSession: parameters.userSession,
@@ -19,8 +19,6 @@ import SFSafeSymbols
import SwiftUI
struct SettingsScreen: View {
@State private var showingLogoutConfirmation = false
@ObservedObject var context: SettingsScreenViewModel.Context
var body: some View {
@@ -196,16 +194,9 @@ struct SettingsScreen: View {
ListRow(label: .default(title: L10n.screenSignoutPreferenceItem,
systemIcon: .rectanglePortraitAndArrowRight),
kind: .button {
showingLogoutConfirmation = true
context.send(viewAction: .logout)
})
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.logout)
.alert(L10n.screenSignoutConfirmationDialogTitle, isPresented: $showingLogoutConfirmation) {
Button(L10n.screenSignoutConfirmationDialogSubmit, role: .destructive) {
context.send(viewAction: .logout)
}
} message: {
Text(L10n.screenSignoutConfirmationDialogContent)
}
} footer: {
VStack {
versionText