mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-30 13:16:58 +02:00
Add error handling for push sync
This commit is contained in:
@@ -21,6 +21,7 @@ import SwiftUI
|
||||
/// Also renders an optional bottom section.
|
||||
/// Used in the case of keywords, for the keyword chips and input.
|
||||
struct NotificationSettings<BottomSection: View>: View {
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
@ObservedObject var viewModel: NotificationSettingsViewModel
|
||||
|
||||
var bottomSection: BottomSection?
|
||||
@@ -31,10 +32,18 @@ struct NotificationSettings<BottomSection: View>: View {
|
||||
header: FormSectionHeader(text: VectorL10n.settingsNotifyMeFor)
|
||||
) {
|
||||
ForEach(viewModel.viewState.ruleIds) { ruleId in
|
||||
let checked = viewModel.viewState.selectionState[ruleId] ?? false
|
||||
FormPickerItem(title: ruleId.title, selected: checked) {
|
||||
Task {
|
||||
await viewModel.update(ruleID: ruleId, isChecked: !checked)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
let checked = viewModel.viewState.selectionState[ruleId] ?? false
|
||||
FormPickerItem(title: ruleId.title, selected: checked) {
|
||||
viewModel.update(ruleID: ruleId, isChecked: !checked)
|
||||
}
|
||||
|
||||
if viewModel.isRuleOutOfSync(ruleId) {
|
||||
Text(VectorL10n.settingsPushRulesError)
|
||||
.font(theme.fonts.caption1)
|
||||
.foregroundColor(theme.colors.alert)
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+28
-2
@@ -147,6 +147,10 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
|
||||
keywordsOrdered = keywordsOrdered.filter { $0 != keyword }
|
||||
notificationSettingsService.remove(keyword: keyword)
|
||||
}
|
||||
|
||||
func isRuleOutOfSync(_ ruleId: NotificationPushRuleId) -> Bool {
|
||||
viewState.outOfSyncRules.contains(ruleId) && viewState.saving == false
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
@@ -206,11 +210,12 @@ private extension NotificationSettingsViewModel {
|
||||
|
||||
@MainActor
|
||||
func completeUpdate() {
|
||||
#warning("Handle error here in the next ticket")
|
||||
viewState.saving = false
|
||||
}
|
||||
|
||||
func rulesUpdated(newRules: [NotificationPushRuleType]) {
|
||||
var outOfSyncRules: Set<NotificationPushRuleId> = .init()
|
||||
|
||||
for rule in newRules {
|
||||
guard
|
||||
let ruleId = NotificationPushRuleId(rawValue: rule.ruleId),
|
||||
@@ -219,8 +224,15 @@ private extension NotificationSettingsViewModel {
|
||||
continue
|
||||
}
|
||||
|
||||
viewState.selectionState[ruleId] = isChecked(rule: rule, syncedRules: ruleId.syncedRules(in: newRules))
|
||||
let relatedSyncedRules = ruleId.syncedRules(in: newRules)
|
||||
viewState.selectionState[ruleId] = isChecked(rule: rule, syncedRules: relatedSyncedRules)
|
||||
|
||||
if isOutOfSync(rule: rule, syncedRules: relatedSyncedRules) {
|
||||
outOfSyncRules.insert(ruleId)
|
||||
}
|
||||
}
|
||||
|
||||
viewState.outOfSyncRules = outOfSyncRules
|
||||
}
|
||||
|
||||
func keywordRuleUpdated(anyEnabled: Bool) {
|
||||
@@ -266,6 +278,20 @@ private extension NotificationSettingsViewModel {
|
||||
return defaultIsChecked(rule: rule)
|
||||
}
|
||||
}
|
||||
|
||||
func isOutOfSync(rule: NotificationPushRuleType, syncedRules: [NotificationPushRuleType]) -> Bool {
|
||||
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId) else {
|
||||
return false
|
||||
}
|
||||
|
||||
switch ruleId {
|
||||
case .oneToOneRoom, .allOtherMessages:
|
||||
let ruleIsChecked = defaultIsChecked(rule: rule)
|
||||
return syncedRules.contains(where: { defaultIsChecked(rule: $0) != ruleIsChecked })
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension NotificationPushRuleId {
|
||||
|
||||
+1
@@ -22,5 +22,6 @@ struct NotificationSettingsViewState {
|
||||
var saving: Bool
|
||||
var ruleIds: [NotificationPushRuleId]
|
||||
var selectionState: [NotificationPushRuleId: Bool]
|
||||
var outOfSyncRules: Set<NotificationPushRuleId> = .init()
|
||||
var keywords = [String]()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user