|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
| 17 | +""" |
| 18 | +Push rules is the system used to determine which events trigger a push (and a |
| 19 | +bump in notification counts). |
| 20 | +
|
| 21 | +This consists of a list of "push rules" for each user, where a push rule is a |
| 22 | +pair of "conditions" and "actions". When a user receives an event Synapse |
| 23 | +iterates over the list of push rules until it finds one where all the conditions |
| 24 | +match the event, at which point "actions" describe the outcome (e.g. notify, |
| 25 | +highlight, etc). |
| 26 | +
|
| 27 | +Push rules are split up into 5 different "kinds" (aka "priority classes"), which |
| 28 | +are run in order: |
| 29 | + 1. Override — highest priority rules, e.g. always ignore notices |
| 30 | + 2. Content — content specific rules, e.g. @ notifications |
| 31 | + 3. Room — per room rules, e.g. enable/disable notifications for all messages |
| 32 | + in a room |
| 33 | + 4. Sender — per sender rules, e.g. never notify for messages from a given |
| 34 | + user |
| 35 | + 5. Underride — the lowest priority "default" rules, e.g. notify for every |
| 36 | + message. |
| 37 | +
|
| 38 | +The set of "base rules" are the list of rules that every user has by default. A |
| 39 | +user can modify their copy of the push rules in one of three ways: |
| 40 | +
|
| 41 | + 1. Adding a new push rule of a certain kind |
| 42 | + 2. Changing the actions of a base rule |
| 43 | + 3. Enabling/disabling a base rule. |
| 44 | +
|
| 45 | +The base rules are split into whether they come before or after a particular |
| 46 | +kind, so the order of push rule evaluation would be: base rules for before |
| 47 | +"override" kind, user defined "override" rules, base rules after "override" |
| 48 | +kind, etc, etc. |
| 49 | +""" |
| 50 | + |
17 | 51 | import itertools
|
18 | 52 | from typing import Dict, Iterator, List, Mapping, Sequence, Tuple, Union
|
19 | 53 |
|
|
25 | 59 |
|
26 | 60 | @attr.s(auto_attribs=True, slots=True, frozen=True)
|
27 | 61 | class PushRule:
|
| 62 | + """A push rule |
| 63 | +
|
| 64 | + Attributes: |
| 65 | + rule_id: a unique ID for this rule |
| 66 | + priority_class: what "kind" of push rule this is (see |
| 67 | + `PRIORITY_CLASS_MAP` for mapping between int and kind) |
| 68 | + conditions: the sequence of conditions that all need to match |
| 69 | + actions: the actions to apply if all conditions are met |
| 70 | + default: is this a base rule? |
| 71 | + default_enabled: is this enabled by default? |
| 72 | + """ |
| 73 | + |
28 | 74 | rule_id: str
|
29 | 75 | priority_class: int
|
30 | 76 | conditions: Sequence[Mapping[str, str]]
|
|
0 commit comments