mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-15 21:52:25 +03:00
Push rule evaluation tweaks (#2897)
This tweaks push rule evaluation: 1. to be more strict around pattern matching and to not match empty patterns 3. to bail if we come across a `dont_notify`, since cycles after that are wasted 4. refactors `ActionsToTweaks` to make a bit more sense
This commit is contained in:
parent
ac5f3f025e
commit
f009e54181
4 changed files with 39 additions and 19 deletions
|
@ -11,22 +11,27 @@ import (
|
|||
// kind and a tweaks map. Returns a nil map if it would have been
|
||||
// empty.
|
||||
func ActionsToTweaks(as []*Action) (ActionKind, map[string]interface{}, error) {
|
||||
kind := UnknownAction
|
||||
tweaks := map[string]interface{}{}
|
||||
var kind ActionKind
|
||||
var tweaks map[string]interface{}
|
||||
|
||||
for _, a := range as {
|
||||
if a.Kind == SetTweakAction {
|
||||
tweaks[string(a.Tweak)] = a.Value
|
||||
continue
|
||||
}
|
||||
if kind != UnknownAction {
|
||||
return UnknownAction, nil, fmt.Errorf("got multiple primary actions: already had %q, got %s", kind, a.Kind)
|
||||
}
|
||||
kind = a.Kind
|
||||
}
|
||||
switch a.Kind {
|
||||
case DontNotifyAction:
|
||||
// Don't bother processing any further
|
||||
return DontNotifyAction, nil, nil
|
||||
|
||||
if len(tweaks) == 0 {
|
||||
tweaks = nil
|
||||
case SetTweakAction:
|
||||
if tweaks == nil {
|
||||
tweaks = map[string]interface{}{}
|
||||
}
|
||||
tweaks[string(a.Tweak)] = a.Value
|
||||
|
||||
default:
|
||||
if kind != UnknownAction {
|
||||
return UnknownAction, nil, fmt.Errorf("got multiple primary actions: already had %q, got %s", kind, a.Kind)
|
||||
}
|
||||
kind = a.Kind
|
||||
}
|
||||
}
|
||||
|
||||
return kind, tweaks, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue