Skip to content

Commit 43cf8b3

Browse files
authored
Merge pull request #1794 from matrix-org/nimau/7576_msc3987_push_actions_cleanup
2 parents fdfc031 + 561e5b2 commit 43cf8b3

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

MatrixSDK/Background/MXBackgroundPushRulesManager.swift

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ import Foundation
8282
return false
8383
}
8484

85+
// Support for MSC3987: The dont_notify push rule action is deprecated.
86+
if rule.actions.isEmpty {
87+
return rule.enabled
88+
}
89+
90+
// Compatibility support.
8591
for ruleAction in rule.actions {
8692
guard let action = ruleAction as? MXPushRuleAction else { continue }
8793
if action.actionType == MXPushRuleActionTypeDontNotify {

MatrixSDK/MXRestClient.m

+7-7
Original file line numberDiff line numberDiff line change
@@ -1816,43 +1816,43 @@ - (MXHTTPOperation *)addPushRule:(NSString*)ruleId
18161816
{
18171817
case MXPushRuleKindOverride:
18181818
kindString = @"override";
1819-
if (conditions.count && actions.count)
1819+
if (conditions.count && actions)
18201820
{
18211821
content = @{@"conditions": conditions, @"actions": actions};
18221822
}
1823-
else if (actions.count)
1823+
else if (actions)
18241824
{
18251825
content = @{@"actions": actions};
18261826
}
18271827
break;
18281828
case MXPushRuleKindContent:
18291829
kindString = @"content";
1830-
if (pattern.length && actions.count)
1830+
if (pattern.length && actions)
18311831
{
18321832
content = @{@"pattern": pattern, @"actions": actions};
18331833
}
18341834
break;
18351835
case MXPushRuleKindRoom:
18361836
kindString = @"room";
1837-
if (actions.count)
1837+
if (actions)
18381838
{
18391839
content = @{@"actions": actions};
18401840
}
18411841
break;
18421842
case MXPushRuleKindSender:
18431843
kindString = @"sender";
1844-
if (actions.count)
1844+
if (actions)
18451845
{
18461846
content = @{@"actions": actions};
18471847
}
18481848
break;
18491849
case MXPushRuleKindUnderride:
18501850
kindString = @"underride";
1851-
if (conditions.count && actions.count)
1851+
if (conditions.count && actions)
18521852
{
18531853
content = @{@"conditions": conditions, @"actions": actions};
18541854
}
1855-
else if (actions.count)
1855+
else if (actions)
18561856
{
18571857
content = @{@"actions": actions};
18581858
}

MatrixSDK/NotificationCenter/MXNotificationCenter.m

+3-5
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ - (NSArray*)encodeActionsWithNotify:(BOOL)notify
579579
highlight:(BOOL)highlight
580580
{
581581
NSMutableArray *actions = [NSMutableArray array];
582+
// Support for MSC3987: The dont_notify push rule action is deprecated and replaced by an empty actions list.
582583
if (notify)
583584
{
584585
[actions addObject:@"notify"];
@@ -597,10 +598,6 @@ - (NSArray*)encodeActionsWithNotify:(BOOL)notify
597598
[actions addObject:@{@"set_tweak": @"highlight", @"value": @NO}];
598599
}
599600
}
600-
else
601-
{
602-
[actions addObject:@"dont_notify"];
603-
}
604601
return actions;
605602
}
606603

@@ -615,7 +612,8 @@ - (void)shouldNotify:(MXEvent*)event roomState:(MXRoomState*)roomState
615612
if (rule)
616613
{
617614
// Make sure this is not a rule to prevent from generating a notification
618-
BOOL actionNotify = YES;
615+
// Support for MSC3987: The dont_notify push rule action is deprecated and replaced by an empty actions list.
616+
BOOL actionNotify = (rule.actions.count > 0);
619617
if (1 == rule.actions.count)
620618
{
621619
MXPushRuleAction *action = rule.actions[0];

MatrixSDK/Space/MXSpaceNotificationCounter.swift

+6
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ public class MXSpaceNotificationCounter: NSObject {
225225
continue
226226
}
227227

228+
// Support for MSC3987: The dont_notify push rule action is deprecated.
229+
if rule.actions.isEmpty {
230+
return rule.enabled
231+
}
232+
233+
// Compatibility support.
228234
for ruleAction in ruleActions where ruleAction.actionType == MXPushRuleActionTypeDontNotify {
229235
return rule.enabled
230236
}

changelog.d/7576.change

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MSC3987 implementation: the 'dont_notify' action for a push_rule is now deprecated and replaced by an empty action list.

0 commit comments

Comments
 (0)