Start poll push rule sync logic

This commit is contained in:
Alfonso Grillo
2023-01-27 18:46:22 +01:00
parent 56c5885686
commit 4474f5beab
@@ -113,12 +113,32 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
switch ruleID {
case .keywords: // Keywords is handled differently to other settings
updateKeywords(isChecked: isChecked)
case .oneToOneRoom:
updatePushActions(for: [ruleID, .oneToOnePollStart, .msc3930oneToOnePollStart, .oneToOnePollEnd, .msc3930oneToOnePollEnd], enabled: enabled, standardActions: standardActions)
updatePushAction(
id: ruleID,
enabled: enabled,
standardActions: standardActions,
then: [.oneToOnePollStart, .msc3930oneToOnePollStart, .oneToOnePollEnd, .msc3930oneToOnePollEnd],
completion: nil
)
case .allOtherMessages:
updatePushActions(for: [ruleID, .pollStart, .msc3930pollStart, .pollEnd, .msc3930pollEnd], enabled: enabled, standardActions: standardActions)
updatePushAction(
id: ruleID,
enabled: enabled,
standardActions: standardActions,
then: [.pollStart, .msc3930pollStart, .pollEnd, .msc3930pollEnd],
completion: nil
)
default:
updatePushActions(for: [ruleID], enabled: enabled, standardActions: standardActions)
notificationSettingsService.updatePushRuleActions(
for: ruleID.rawValue,
enabled: enabled,
actions: standardActions.actions,
completion: nil
)
}
}
@@ -157,6 +177,27 @@ private extension NotificationSettingsViewModel {
)
}
}
func updatePushAction(id: NotificationPushRuleId,
enabled: Bool,
standardActions: NotificationStandardActions,
then rules: [NotificationPushRuleId],
completion: ((Result<Void, Error>) -> Void)?) {
notificationSettingsService.updatePushRuleActions(
for: id.rawValue,
enabled: enabled,
actions: standardActions.actions) { [weak self] result in
switch result {
case .success:
#warning("TODO: sync the update of these rules with the completion")
self?.updatePushActions(for: rules, enabled: enabled, standardActions: standardActions)
completion?(.success(()))
case .failure(let error):
completion?(.failure(error))
}
}
}
func updatePushActions(for ids: [NotificationPushRuleId], enabled: Bool, standardActions: NotificationStandardActions) {
for id in ids {