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
This commit is contained in:
parent
fd2f90903f
commit
989a1cd504
|
|
@ -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),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue