#1899, #1900, #1901 - Implement chat backup setting screens

This commit is contained in:
Stefan Ceriu
2023-10-19 15:34:10 +03:00
committed by GitHub
parent 15b5b44422
commit c8b9d95122
70 changed files with 2293 additions and 48 deletions
@@ -24,6 +24,7 @@ struct SettingsScreenCoordinatorParameters {
let appLockService: AppLockServiceProtocol
let bugReportService: BugReportServiceProtocol
let notificationSettings: NotificationSettingsProxyProtocol
let secureBackupController: SecureBackupControllerProtocol
let appSettings: AppSettings
}
@@ -49,7 +50,8 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
init(parameters: SettingsScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = SettingsScreenViewModel(userSession: parameters.userSession, appSettings: parameters.appSettings)
viewModel = SettingsScreenViewModel(userSession: parameters.userSession,
appSettings: parameters.appSettings)
viewModel.actions
.sink { [weak self] action in
@@ -71,7 +73,9 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
case .about:
presentLegalInformationScreen()
case .sessionVerification:
verifySession()
presentSessionVerificationScreen()
case .secureBackup:
presentSecureBackupScreen()
case .accountSessionsList:
presentAccountSessionsListURL()
case .notifications:
@@ -172,7 +176,7 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
parameters.navigationStackCoordinator?.push(LegalInformationScreenCoordinator(appSettings: parameters.appSettings))
}
private func verifySession() {
private func presentSessionVerificationScreen() {
guard let sessionVerificationController = parameters.userSession.sessionVerificationController else {
fatalError("The sessionVerificationController should aways be valid at this point")
}
@@ -196,6 +200,15 @@ 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,
@@ -26,6 +26,7 @@ enum SettingsScreenViewModelAction {
case reportBug
case about
case sessionVerification
case secureBackup
case accountSessionsList
case notifications
case advancedSettings
@@ -40,7 +41,9 @@ struct SettingsScreenViewState: BindableState {
var accountSessionsListURL: URL?
var userAvatarURL: URL?
var userDisplayName: String?
var showSessionVerificationSection: Bool
var isSessionVerified: Bool
var chatBackupEnabled = false
var showSecureBackupBadge = false
var showAppLockSettings: Bool
var showDeveloperOptions: Bool
@@ -57,6 +60,7 @@ enum SettingsScreenViewAction {
case reportBug
case about
case sessionVerification
case secureBackup
case accountSessionsList
case notifications
case developerOptions
@@ -33,16 +33,16 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
self.userSession = userSession
self.appSettings = appSettings
var showSessionVerificationSection = false
var isSessionVerified = true
if let sessionVerificationController = userSession.sessionVerificationController {
showSessionVerificationSection = !sessionVerificationController.isVerified
isSessionVerified = sessionVerificationController.isVerified
}
super.init(initialViewState: .init(deviceID: userSession.deviceID,
userID: userSession.userID,
accountProfileURL: userSession.clientProxy.accountURL(action: .profile),
accountSessionsListURL: userSession.clientProxy.accountURL(action: .sessionsList),
showSessionVerificationSection: showSessionVerificationSection,
isSessionVerified: isSessionVerified,
showAppLockSettings: appSettings.appLockFlowEnabled,
showDeveloperOptions: appSettings.canShowDeveloperOptions),
imageProvider: userSession.mediaProvider)
@@ -56,11 +56,24 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
.receive(on: DispatchQueue.main)
.weakAssign(to: \.state.userDisplayName, on: self)
.store(in: &cancellables)
appSettings.$appLockFlowEnabled
.weakAssign(to: \.state.showAppLockSettings, on: self)
.store(in: &cancellables)
appSettings.$chatBackupEnabled
.weakAssign(to: \.state.chatBackupEnabled, on: self)
.store(in: &cancellables)
userSession.clientProxy.secureBackupController.recoveryKeyState
.receive(on: DispatchQueue.main)
.sink { [weak self] state in
guard let self else { return }
self.state.showSecureBackupBadge = (state == .unknown || state == .disabled) && appSettings.chatBackupEnabled
}
.store(in: &cancellables)
Task {
await userSession.clientProxy.loadUserAvatarURL()
await userSession.clientProxy.loadUserDisplayName()
@@ -71,9 +84,9 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
.sink { [weak self] callback in
switch callback {
case .sessionVerificationNeeded:
self?.state.showSessionVerificationSection = true
self?.state.isSessionVerified = false
case .didVerifySession:
self?.state.showSessionVerificationSection = false
self?.state.isSessionVerified = true
default:
break
}
@@ -101,6 +114,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
actionsSubject.send(.logout)
case .sessionVerification:
actionsSubject.send(.sessionVerification)
case .secureBackup:
actionsSubject.send(.secureBackup)
case .notifications:
actionsSubject.send(.notifications)
case .accountSessionsList:
@@ -27,9 +27,7 @@ struct SettingsScreen: View {
Form {
userSection
if context.viewState.showSessionVerificationSection {
sessionVerificationSection
}
accountSecuritySection
mainSection
@@ -86,11 +84,22 @@ struct SettingsScreen: View {
}
}
private var sessionVerificationSection: some View {
Section {
ListRow(label: .default(title: L10n.actionCompleteVerification,
systemIcon: .checkmarkShield),
kind: .button { context.send(viewAction: .sessionVerification) })
@ViewBuilder
private var accountSecuritySection: some View {
if !context.viewState.isSessionVerified || context.viewState.chatBackupEnabled {
Section {
if !context.viewState.isSessionVerified {
ListRow(label: .default(title: L10n.actionCompleteVerification,
systemIcon: .checkmarkShield),
kind: .button { context.send(viewAction: .sessionVerification) })
} else if context.viewState.chatBackupEnabled {
ListRow(label: .default(title: L10n.commonChatBackup,
icon: Image(asset: Asset.Images.secureBackupIcon)),
details: context.viewState.showSecureBackupBadge ? .icon(secureBackupBadge) : nil,
kind: .navigationLink { context.send(viewAction: .secureBackup) })
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.secureBackup)
}
}
}
}
@@ -222,6 +231,13 @@ struct SettingsScreen: View {
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.done)
}
}
@ViewBuilder
private var secureBackupBadge: some View {
if context.viewState.showSecureBackupBadge {
BadgeView(size: 10)
}
}
}
private extension TimelineStyle {