fix: Skip rules with unknown conditions

Without this, when new rules are added with new conditions, we would
always match on them. This would mean all messages now notify. It is
better to skip them instead.
This commit is contained in:
Nicolas Werner 2023-04-26 19:00:24 +02:00
parent 970551d8cb
commit 831938b8f5
No known key found for this signature in database
2 changed files with 25 additions and 0 deletions

View File

@ -186,6 +186,8 @@ class _OptimizedRules {
notificationPermissions.add(key); notificationPermissions.add(key);
} }
break; break;
default:
throw Exception('Unknown push condition: ${condition.kind}');
} }
} }
actions = EvaluatedPushRuleAction.fromActions(rule.actions); actions = EvaluatedPushRuleAction.fromActions(rule.actions);

View File

@ -208,6 +208,29 @@ void main() {
testNotMatch(override_ruleset2, event); testNotMatch(override_ruleset2, event);
}); });
test('invalid push condition', () async {
final invalid_ruleset = PushRuleSet(override: [
PushRule(ruleId: 'my.rule', default$: false, enabled: true, actions: [
'notify',
{'set_tweak': 'highlight', 'value': true},
{'set_tweak': 'sound', 'value': 'goose.wav'},
], conditions: [
PushCondition(
kind: 'invalidcondition', pattern: 'fox', key: 'content.body'),
])
]);
expect(() => PushruleEvaluator.fromRuleset(invalid_ruleset),
returnsNormally);
final evaluator = PushruleEvaluator.fromRuleset(invalid_ruleset);
final event = Event.fromJson(jsonObj, room);
final actions = evaluator.match(event);
expect(actions.highlight, false);
expect(actions.sound, null);
expect(actions.notify, false);
});
test('match_display_name rule', () async { test('match_display_name rule', () async {
final event = Event.fromJson(jsonObj, room); final event = Event.fromJson(jsonObj, room);
(event.room.states[EventTypes.RoomMember] ??= {})[client.userID!] = (event.room.states[EventTypes.RoomMember] ??= {})[client.userID!] =