| 118 | } |
| 119 | |
| 120 | func conditionMatches(cond *Condition, event *gomatrixserverlib.Event, ec EvaluationContext) (bool, error) { |
| 121 | switch cond.Kind { |
| 122 | case EventMatchCondition: |
| 123 | return patternMatches(cond.Key, cond.Pattern, event) |
| 124 | |
| 125 | case ContainsDisplayNameCondition: |
| 126 | return patternMatches("content.body", ec.UserDisplayName(), event) |
| 127 | |
| 128 | case RoomMemberCountCondition: |
| 129 | cmp, err := parseRoomMemberCountCondition(cond.Is) |
| 130 | if err != nil { |
| 131 | return false, fmt.Errorf("parsing room_member_count condition: %w", err) |
| 132 | } |
| 133 | n, err := ec.RoomMemberCount() |
| 134 | if err != nil { |
| 135 | return false, fmt.Errorf("RoomMemberCount failed: %w", err) |
| 136 | } |
| 137 | return cmp(n), nil |
| 138 | |
| 139 | case SenderNotificationPermissionCondition: |
| 140 | return ec.HasPowerLevel(event.Sender(), cond.Key) |
| 141 | |
| 142 | default: |
| 143 | return false, nil |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | func patternMatches(key, pattern string, event *gomatrixserverlib.Event) (bool, error) { |
| 148 | re, err := globToRegexp(pattern) |