Skip to content

Commit

Permalink
Merge pull request matrix-org#1794 from matrix-org/nimau/7576_msc3987…
Browse files Browse the repository at this point in the history
…_push_actions_cleanup
  • Loading branch information
nimau authored Jun 7, 2023
2 parents fdfc031 + 561e5b2 commit 43cf8b3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions MatrixSDK/Background/MXBackgroundPushRulesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions MatrixSDK/MXRestClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down
8 changes: 3 additions & 5 deletions MatrixSDK/NotificationCenter/MXNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -597,10 +598,6 @@ - (NSArray*)encodeActionsWithNotify:(BOOL)notify
[actions addObject:@{@"set_tweak": @"highlight", @"value": @NO}];
}
}
else
{
[actions addObject:@"dont_notify"];
}
return actions;
}

Expand All @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions MatrixSDK/Space/MXSpaceNotificationCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions changelog.d/7576.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MSC3987 implementation: the 'dont_notify' action for a push_rule is now deprecated and replaced by an empty action list.

0 comments on commit 43cf8b3

Please sign in to comment.