| 84 | } |
| 85 | |
| 86 | func ruleMatches(rule *Rule, kind Kind, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) { |
| 87 | if !rule.Enabled { |
| 88 | return false, nil |
| 89 | } |
| 90 | |
| 91 | switch kind { |
| 92 | case OverrideKind, UnderrideKind: |
| 93 | for _, cond := range rule.Conditions { |
| 94 | ok, err := conditionMatches(cond, event, ec) |
| 95 | if err != nil { |
| 96 | return false, err |
| 97 | } |
| 98 | if !ok { |
| 99 | return false, nil |
| 100 | } |
| 101 | } |
| 102 | return true, nil |
| 103 | |
| 104 | case ContentKind: |
| 105 | // TODO: "These configure behaviour for (unencrypted) messages |
| 106 | // that match certain patterns." - Does that mean "content.body"? |
| 107 | return patternMatches("content.body", rule.Pattern, event) |
| 108 | |
| 109 | case RoomKind: |
| 110 | return rule.RuleID == event.RoomID(), nil |
| 111 | |
| 112 | case SenderKind: |
| 113 | return rule.RuleID == event.Sender(), nil |
| 114 | |
| 115 | default: |
| 116 | return false, nil |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func conditionMatches(cond *Condition, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) { |
| 121 | switch cond.Kind { |