Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MSC3987: Push actions clean-up #1794

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.