diff --git a/MatrixSDK/Background/MXBackgroundPushRulesManager.swift b/MatrixSDK/Background/MXBackgroundPushRulesManager.swift index 34d386ad2..da793d2ee 100644 --- a/MatrixSDK/Background/MXBackgroundPushRulesManager.swift +++ b/MatrixSDK/Background/MXBackgroundPushRulesManager.swift @@ -82,6 +82,12 @@ import Foundation return false } + // Support for MSC3987: The dont_notify push rule action is deprecated. + if rule.actions.isEmpty { + return rule.enabled + } + + // Compatibility support. for ruleAction in rule.actions { guard let action = ruleAction as? MXPushRuleAction else { continue } if action.actionType == MXPushRuleActionTypeDontNotify { diff --git a/MatrixSDK/MXRestClient.m b/MatrixSDK/MXRestClient.m index 38f38c3a0..799514b86 100644 --- a/MatrixSDK/MXRestClient.m +++ b/MatrixSDK/MXRestClient.m @@ -1816,43 +1816,43 @@ - (MXHTTPOperation *)addPushRule:(NSString*)ruleId { case MXPushRuleKindOverride: kindString = @"override"; - if (conditions.count && actions.count) + if (conditions.count && actions) { content = @{@"conditions": conditions, @"actions": actions}; } - else if (actions.count) + else if (actions) { content = @{@"actions": actions}; } break; case MXPushRuleKindContent: kindString = @"content"; - if (pattern.length && actions.count) + if (pattern.length && actions) { content = @{@"pattern": pattern, @"actions": actions}; } break; case MXPushRuleKindRoom: kindString = @"room"; - if (actions.count) + if (actions) { content = @{@"actions": actions}; } break; case MXPushRuleKindSender: kindString = @"sender"; - if (actions.count) + if (actions) { content = @{@"actions": actions}; } break; case MXPushRuleKindUnderride: kindString = @"underride"; - if (conditions.count && actions.count) + if (conditions.count && actions) { content = @{@"conditions": conditions, @"actions": actions}; } - else if (actions.count) + else if (actions) { content = @{@"actions": actions}; } diff --git a/MatrixSDK/NotificationCenter/MXNotificationCenter.m b/MatrixSDK/NotificationCenter/MXNotificationCenter.m index 1e80429ea..d15373982 100644 --- a/MatrixSDK/NotificationCenter/MXNotificationCenter.m +++ b/MatrixSDK/NotificationCenter/MXNotificationCenter.m @@ -579,6 +579,7 @@ - (NSArray*)encodeActionsWithNotify:(BOOL)notify highlight:(BOOL)highlight { NSMutableArray *actions = [NSMutableArray array]; + // Support for MSC3987: The dont_notify push rule action is deprecated and replaced by an empty actions list. if (notify) { [actions addObject:@"notify"]; @@ -597,10 +598,6 @@ - (NSArray*)encodeActionsWithNotify:(BOOL)notify [actions addObject:@{@"set_tweak": @"highlight", @"value": @NO}]; } } - else - { - [actions addObject:@"dont_notify"]; - } return actions; } @@ -615,7 +612,8 @@ - (void)shouldNotify:(MXEvent*)event roomState:(MXRoomState*)roomState if (rule) { // Make sure this is not a rule to prevent from generating a notification - BOOL actionNotify = YES; + // Support for MSC3987: The dont_notify push rule action is deprecated and replaced by an empty actions list. + BOOL actionNotify = (rule.actions.count > 0); if (1 == rule.actions.count) { MXPushRuleAction *action = rule.actions[0]; diff --git a/MatrixSDK/Space/MXSpaceNotificationCounter.swift b/MatrixSDK/Space/MXSpaceNotificationCounter.swift index a27e1bbcd..953b67755 100644 --- a/MatrixSDK/Space/MXSpaceNotificationCounter.swift +++ b/MatrixSDK/Space/MXSpaceNotificationCounter.swift @@ -225,6 +225,12 @@ public class MXSpaceNotificationCounter: NSObject { continue } + // Support for MSC3987: The dont_notify push rule action is deprecated. + if rule.actions.isEmpty { + return rule.enabled + } + + // Compatibility support. for ruleAction in ruleActions where ruleAction.actionType == MXPushRuleActionTypeDontNotify { return rule.enabled } diff --git a/changelog.d/7576.change b/changelog.d/7576.change new file mode 100644 index 000000000..26f9e7695 --- /dev/null +++ b/changelog.d/7576.change @@ -0,0 +1 @@ +MSC3987 implementation: the 'dont_notify' action for a push_rule is now deprecated and replaced by an empty action list.