From 989a1cd5045acea49a1436a547290dfbd23969cd Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 20 Nov 2024 10:48:06 +0100 Subject: [PATCH] refactor: Do not set the deprecated dont_notify action in push rules This has been deprecated since https://spec.matrix.org/v1.7/client-server-api/#actions An empty list of actions should now be equal to a list with the entry "dont_notify". Clients should ignore this action and use empty lists instead. A good explaination can be found https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/3987-push-actions-clean-up.md --- lib/src/room.dart | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 10b9db30..98995057 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -2090,16 +2090,22 @@ class Room { /// Returns the [PushRuleState] for this room, based on the m.push_rules stored in /// the account_data. PushRuleState get pushRuleState { - final globalPushRules = - client.accountData['m.push_rules']?.content['global']; - if (globalPushRules is! Map) { + final globalPushRules = client.globalPushRules; + if (globalPushRules == null) { + // We have no push rules specified at all so we fallback to just notify: return PushRuleState.notify; } - if (globalPushRules['override'] is List) { - for (final pushRule in globalPushRules['override']) { - if (pushRule['rule_id'] == id) { - if (pushRule['actions'].indexOf('dont_notify') != -1) { + final overridePushRules = globalPushRules.override; + if (overridePushRules != null) { + for (final pushRule in overridePushRules) { + if (pushRule.ruleId == id) { + // "dont_notify" and "coalesce" should be ignored in actions since + // https://spec.matrix.org/v1.7/client-server-api/#actions + pushRule.actions + ..remove('dont_notify') + ..remove('coalesce'); + if (pushRule.actions.isEmpty) { return PushRuleState.dontNotify; } break; @@ -2107,10 +2113,16 @@ class Room { } } - if (globalPushRules['room'] is List) { - for (final pushRule in globalPushRules['room']) { - if (pushRule['rule_id'] == id) { - if (pushRule['actions'].indexOf('dont_notify') != -1) { + final roomPushRules = globalPushRules.room; + if (roomPushRules != null) { + for (final pushRule in roomPushRules) { + if (pushRule.ruleId == id) { + // "dont_notify" and "coalesce" should be ignored in actions since + // https://spec.matrix.org/v1.7/client-server-api/#actions + pushRule.actions + ..remove('dont_notify') + ..remove('coalesce'); + if (pushRule.actions.isEmpty) { return PushRuleState.mentionsOnly; } break; @@ -2142,13 +2154,13 @@ class Room { await client.setPushRule( PushRuleKind.room, id, - [PushRuleAction.dontNotify], + [], ); } else if (pushRuleState == PushRuleState.notify) { await client.setPushRule( PushRuleKind.room, id, - [PushRuleAction.dontNotify], + [], ); } break; @@ -2160,7 +2172,7 @@ class Room { await client.setPushRule( PushRuleKind.override, id, - [PushRuleAction.dontNotify], + [], conditions: [ PushCondition(kind: 'event_match', key: 'room_id', pattern: id), ],