Merge pull request #1957 from famedly/krille/do-not-send-deprecated-dont-notify-actions

refactor: Do not set the deprecated dont_notify action in push rules
This commit is contained in:
Krille-chan 2024-11-25 14:14:55 +01:00 committed by GitHub
commit 708144aeea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 14 deletions

View File

@ -2090,16 +2090,22 @@ class Room {
/// Returns the [PushRuleState] for this room, based on the m.push_rules stored in /// Returns the [PushRuleState] for this room, based on the m.push_rules stored in
/// the account_data. /// the account_data.
PushRuleState get pushRuleState { PushRuleState get pushRuleState {
final globalPushRules = final globalPushRules = client.globalPushRules;
client.accountData['m.push_rules']?.content['global']; if (globalPushRules == null) {
if (globalPushRules is! Map) { // We have no push rules specified at all so we fallback to just notify:
return PushRuleState.notify; return PushRuleState.notify;
} }
if (globalPushRules['override'] is List) { final overridePushRules = globalPushRules.override;
for (final pushRule in globalPushRules['override']) { if (overridePushRules != null) {
if (pushRule['rule_id'] == id) { for (final pushRule in overridePushRules) {
if (pushRule['actions'].indexOf('dont_notify') != -1) { 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; return PushRuleState.dontNotify;
} }
break; break;
@ -2107,10 +2113,16 @@ class Room {
} }
} }
if (globalPushRules['room'] is List) { final roomPushRules = globalPushRules.room;
for (final pushRule in globalPushRules['room']) { if (roomPushRules != null) {
if (pushRule['rule_id'] == id) { for (final pushRule in roomPushRules) {
if (pushRule['actions'].indexOf('dont_notify') != -1) { 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; return PushRuleState.mentionsOnly;
} }
break; break;
@ -2142,13 +2154,13 @@ class Room {
await client.setPushRule( await client.setPushRule(
PushRuleKind.room, PushRuleKind.room,
id, id,
[PushRuleAction.dontNotify], [],
); );
} else if (pushRuleState == PushRuleState.notify) { } else if (pushRuleState == PushRuleState.notify) {
await client.setPushRule( await client.setPushRule(
PushRuleKind.room, PushRuleKind.room,
id, id,
[PushRuleAction.dontNotify], [],
); );
} }
break; break;
@ -2160,7 +2172,7 @@ class Room {
await client.setPushRule( await client.setPushRule(
PushRuleKind.override, PushRuleKind.override,
id, id,
[PushRuleAction.dontNotify], [],
conditions: [ conditions: [
PushCondition(kind: 'event_match', key: 'room_id', pattern: id), PushCondition(kind: 'event_match', key: 'room_id', pattern: id),
], ],