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 #7585

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
56 changes: 44 additions & 12 deletions Riot/Categories/MXRoom+Riot.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ - (BOOL)isMute
// Check whether an override rule has been defined with the roomm id as rule id.
// This kind of rule is created to mute the room
MXPushRule* rule = [self getOverrideRoomPushRule];
if (rule)
if (rule && rule.enabled)
{
// Support for MSC3987: The dont_notify push rule action is deprecated.
if (rule.actions.count == 0)
{
return true;
}

// Support deprecated dont_notify push rule action for compatibility purposes.
for (MXPushRuleAction *ruleAction in rule.actions)
{
if (ruleAction.actionType == MXPushRuleActionTypeDontNotify)
Expand All @@ -98,7 +105,7 @@ - (BOOL)isMute

if (key && pattern && [key isEqualToString:@"room_id"] && [pattern isEqualToString:self.roomId])
{
return rule.enabled;
return true;
}
}
}
Expand All @@ -113,13 +120,20 @@ - (BOOL)isMentionsOnly
{
// Check push rules at room level
MXPushRule *rule = [self getRoomPushRule];
if (rule)
if (rule && rule.enabled)
{
// Support for MSC3987: The dont_notify push rule action is deprecated.
if (rule.actions.count == 0)
{
return true;
}

// Support deprecated dont_notify push rule action for compatibility purposes.
for (MXPushRuleAction *ruleAction in rule.actions)
{
if (ruleAction.actionType == MXPushRuleActionTypeDontNotify)
{
return rule.enabled;
return true;
}
}
}
Expand Down Expand Up @@ -178,12 +192,21 @@ - (void)mute:(void (^)(void))completion
// check if the user did not define one
BOOL hasDontNotifyRule = NO;

for (MXPushRuleAction *ruleAction in rule.actions)
// Support for MSC3987: The dont_notify push rule action is deprecated.
if (rule.actions.count == 0)
{
if (ruleAction.actionType == MXPushRuleActionTypeDontNotify)
hasDontNotifyRule = YES;
}
else
{
// Support deprecated dont_notify push rule action for compatibility purposes.
for (MXPushRuleAction *ruleAction in rule.actions)
{
hasDontNotifyRule = YES;
break;
if (ruleAction.actionType == MXPushRuleActionTypeDontNotify)
{
hasDontNotifyRule = YES;
break;
}
}
}

Expand Down Expand Up @@ -256,12 +279,21 @@ - (void)mentionsOnly:(void (^)(void))completion
// check if the user did not define one
BOOL hasDontNotifyRule = NO;

for (MXPushRuleAction *ruleAction in rule.actions)
// Support for MSC3987: The dont_notify push rule action is deprecated.
if (rule.actions.count == 0)
{
if (ruleAction.actionType == MXPushRuleActionTypeDontNotify)
hasDontNotifyRule = YES;
}
else
{
// Support deprecated dont_notify push rule action for compatibility purposes.
for (MXPushRuleAction *ruleAction in rule.actions)
{
hasDontNotifyRule = YES;
break;
if (ruleAction.actionType == MXPushRuleActionTypeDontNotify)
{
hasDontNotifyRule = YES;
break;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion RiotNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ class NotificationService: UNNotificationServiceExtension {
private extension MXPushRule {
var dontNotify: Bool {
let actions = (actions as? [MXPushRuleAction]) ?? []
return actions.contains { $0.actionType == MXPushRuleActionTypeDontNotify }
// Support for MSC3987: The dont_notify push rule action is deprecated and replaced by an empty actions list.
return actions.isEmpty || actions.contains { $0.actionType == MXPushRuleActionTypeDontNotify }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
}

// if the user defined one, use it
if rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify) {
if rule.dontNotify {
enablePushRule(rule: rule, completion: completion)
} else {
removePushRule(rule: rule) {
Expand Down Expand Up @@ -136,7 +136,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
}

// if the user defined one, use it
if rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify) {
if rule.dontNotify {
enablePushRule(rule: rule, completion: completion)
} else {
removePushRule(rule: rule) {
Expand Down Expand Up @@ -261,7 +261,7 @@ public extension MXRoom {
// Check whether an override rule has been defined with the roomm id as rule id.
// This kind of rule is created to mute the room
guard let rule = overridePushRule,
rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify),
rule.dontNotify,
rule.conditionIsEnabled(kind: .eventMatch, for: roomId) else {
return false
}
Expand All @@ -271,7 +271,7 @@ public extension MXRoom {
var isMentionsOnly: Bool {
// Check push rules at room level
guard let rule = roomPushRule else { return false }
return rule.enabled && rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify)
return rule.enabled && rule.dontNotify
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ extension MXPushRule: NotificationPushRuleType {
}

var dontNotify: Bool {
getAction(actionType: MXPushRuleActionTypeDontNotify) != nil
guard let actions = actions as? [MXPushRuleAction] else {
return true
}
// Support for MSC3987: The dont_notify push rule action is deprecated and replaced by an empty actions list.
return actions.isEmpty || getAction(actionType: MXPushRuleActionTypeDontNotify) != nil
}
}
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.