Add NotificationPushRuleType.pushRuleId

This commit is contained in:
Alfonso Grillo
2023-02-02 15:18:52 +01:00
parent fa6ea2d4a6
commit d269fb726d
3 changed files with 14 additions and 8 deletions
@@ -21,3 +21,9 @@ protocol NotificationPushRuleType {
var enabled: Bool { get }
func matches(standardActions: NotificationStandardActions?) -> Bool
}
extension NotificationPushRuleType {
var pushRuleId: NotificationPushRuleId? {
ruleId.flatMap(NotificationPushRuleId.init(rawValue:))
}
}
@@ -218,7 +218,7 @@ private extension NotificationSettingsViewModel {
for rule in newRules {
guard
let ruleId = NotificationPushRuleId(rawValue: rule.ruleId),
let ruleId = rule.pushRuleId,
ruleIds.contains(ruleId)
else {
continue
@@ -248,7 +248,7 @@ private extension NotificationSettingsViewModel {
/// - Parameter rule: The push rule type to check.
/// - Returns: Wether it should be displayed as checked or not checked.
func defaultIsChecked(rule: NotificationPushRuleType) -> Bool {
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId) else {
guard let ruleId = rule.pushRuleId else {
return false
}
@@ -264,7 +264,7 @@ private extension NotificationSettingsViewModel {
}
func isChecked(rule: NotificationPushRuleType, syncedRules: [NotificationPushRuleType]) -> Bool {
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId) else {
guard let ruleId = rule.pushRuleId else {
return false
}
@@ -280,7 +280,7 @@ private extension NotificationSettingsViewModel {
}
func isOutOfSync(rule: NotificationPushRuleType, syncedRules: [NotificationPushRuleType]) -> Bool {
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId) else {
guard let ruleId = rule.pushRuleId else {
return false
}
@@ -297,7 +297,7 @@ private extension NotificationSettingsViewModel {
extension NotificationPushRuleId {
func syncedRules(in rules: [NotificationPushRuleType]) -> [NotificationPushRuleType] {
rules.filter {
guard let ruleId = NotificationPushRuleId(rawValue: $0.ruleId) else {
guard let ruleId = $0.pushRuleId else {
return false
}
return syncedRules.contains(ruleId)