1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
//! Types for the the *m.push_rules* event.

use std::{
    fmt::{Display, Formatter, Result as FmtResult},
    str::FromStr,
};

use ruma_events_macros::ruma_event;
use serde::{
    de::{Error, Visitor},
    ser::SerializeStruct as _,
    Deserialize, Deserializer, Serialize, Serializer,
};
use serde_json::{from_value, Value};

use crate::{util::default_true, FromStrError};

ruma_event! {
    /// Describes all push rules for a user.
    PushRulesEvent {
        kind: Event,
        event_type: "m.push_rules",
        content: {
            /// The global ruleset.
            pub global: Ruleset,
        },
    }
}

/// A push ruleset scopes a set of rules according to some criteria.
///
/// For example, some rules may only be applied for messages from a particular sender, a particular
/// room, or by default. The push ruleset contains the entire set of scopes and rules.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Ruleset {
    /// These rules configure behaviour for (unencrypted) messages that match certain patterns.
    pub content: Vec<PatternedPushRule>,

    /// These user-configured rules are given the highest priority.
    #[serde(rename = "override")]
    pub override_rules: Vec<ConditionalPushRule>,

    /// These rules change the behaviour of all messages for a given room.
    pub room: Vec<PushRule>,

    /// These rules configure notification behaviour for messages from a specific Matrix user ID.
    pub sender: Vec<PushRule>,

    /// These rules are identical to override rules, but have a lower priority than `content`,
    /// `room` and `sender` rules.
    pub underride: Vec<ConditionalPushRule>,
}

/// A push rule is a single rule that states under what conditions an event should be passed onto a
/// push gateway and how the notification should be presented.
///
/// These rules are stored on the user's homeserver. They are manually configured by the user, who
/// can create and view them via the Client/Server API.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct PushRule {
    /// Actions to determine if and how a notification is delivered for events matching this rule.
    pub actions: Vec<Action>,

    /// Whether this is a default rule, or has been set explicitly.
    pub default: bool,

    /// Whether the push rule is enabled or not.
    pub enabled: bool,

    /// The ID of this rule.
    pub rule_id: String,
}

/// Like `PushRule`, but with an additional `conditions` field.
///
/// Only applicable to underride and override rules.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ConditionalPushRule {
    /// Actions to determine if and how a notification is delivered for events matching this rule.
    pub actions: Vec<Action>,

    /// Whether this is a default rule, or has been set explicitly.
    pub default: bool,

    /// Whether the push rule is enabled or not.
    pub enabled: bool,

    /// The ID of this rule.
    pub rule_id: String,

    /// The conditions that must hold true for an event in order for a rule to be applied to an event.
    ///
    /// A rule with no conditions always matches.
    pub conditions: Vec<PushCondition>,
}

/// Like `PushRule`, but with an additional `pattern` field.
///
/// Only applicable to content rules.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct PatternedPushRule {
    /// Actions to determine if and how a notification is delivered for events matching this rule.
    pub actions: Vec<Action>,

    /// Whether this is a default rule, or has been set explicitly.
    pub default: bool,

    /// Whether the push rule is enabled or not.
    pub enabled: bool,

    /// The ID of this rule.
    pub rule_id: String,

    /// The glob-style pattern to match against.
    pub pattern: String,
}

/// An action affects if and how a notification is delivered for a matching event.
#[derive(Clone, Debug, PartialEq)]
pub enum Action {
    /// This causes each matching event to generate a notification.
    Notify,

    /// This prevents each matching event from generating a notification.
    DontNotify,

    /// This enables notifications for matching events but activates homeserver specific behaviour
    /// to intelligently coalesce multiple events into a single notification.
    ///
    /// Not all homeservers may support this. Those that do not support it should treat it as the
    /// `notify` action.
    Coalesce,

    /// Sets an entry in the `tweaks` dictionary key that is sent in the notification request to the
    /// Push Gateway. This takes the form of a dictionary with a `set_tweak` key whose value is the
    /// name of the tweak to set. It may also have a `value` key which is the value to which it
    /// should be set.
    SetTweak(Tweak),

    /// Additional variants may be added in the future and will not be considered breaking changes
    /// to ruma-events.
    #[doc(hidden)]
    __Nonexhaustive,
}

impl Display for Action {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        let variant = match *self {
            Action::Notify => "notify",
            Action::DontNotify => "dont_notify",
            Action::Coalesce => "coalesce",
            Action::SetTweak(_) => "set_tweak",
            Action::__Nonexhaustive => {
                panic!("__Nonexhaustive enum variant is not intended for use.")
            }
        };

        write!(f, "{}", variant)
    }
}

impl FromStr for Action {
    type Err = FromStrError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let action = match s {
            "notify" => Action::Notify,
            "dont_notify" => Action::DontNotify,
            "coalesce" => Action::Coalesce,
            _ => return Err(FromStrError),
        };

        Ok(action)
    }
}

impl Serialize for Action {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match *self {
            Action::Notify => serializer.serialize_str("notify"),
            Action::DontNotify => serializer.serialize_str("dont_notify"),
            Action::Coalesce => serializer.serialize_str("coalesce"),
            Action::SetTweak(ref tweak) => tweak.serialize(serializer),
            _ => panic!("Attempted to serialize __Nonexhaustive variant."),
        }
    }
}

impl<'de> Deserialize<'de> for Action {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        struct StringOrStruct;

        impl<'de> Visitor<'de> for StringOrStruct {
            type Value = Action;

            fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
                formatter.write_str("action as string or map")
            }

            fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
            where
                E: serde::de::Error,
            {
                match FromStr::from_str(value) {
                    Ok(action) => Ok(action),
                    Err(_) => Err(serde::de::Error::custom("not a string action")),
                }
            }

            fn visit_map<M>(self, map: M) -> Result<Self::Value, M::Error>
            where
                M: serde::de::MapAccess<'de>,
            {
                match Tweak::deserialize(serde::de::value::MapAccessDeserializer::new(map)) {
                    Ok(tweak) => Ok(Action::SetTweak(tweak)),
                    Err(_) => Err(serde::de::Error::custom("unknown action")),
                }
            }
        }

        deserializer.deserialize_any(StringOrStruct)
    }
}

/// Values for the `set_tweak` action.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(tag = "set_tweak")]
pub enum Tweak {
    /// A string representing the sound to be played when this notification arrives.
    ///
    /// A value of "default" means to play a default sound. A device may choose to alert the user by
    /// some other means if appropriate, eg. vibration.
    #[serde(rename = "sound")]
    Sound {
        /// The sound to be played.
        value: String,
    },

    /// A boolean representing whether or not this message should be highlighted in the UI.
    ///
    /// This will normally take the form of presenting the message in a different color and/or
    /// style. The UI might also be adjusted to draw particular attention to the room in which the
    /// event occurred. If a `highlight` tweak is given with no value, its value is defined to be
    /// `true`. If no highlight tweak is given at all then the value of `highlight` is defined to be
    /// `false`.
    #[serde(rename = "highlight")]
    Highlight {
        /// Whether or not the message should be highlighted.
        #[serde(default = "default_true")]
        value: bool,
    },
}

/// A condition that must apply for an associated push rule's action to be taken.
#[derive(Clone, Debug, PartialEq)]
pub enum PushCondition {
    /// This is a glob pattern match on a field of the event.
    EventMatch(EventMatchCondition),

    /// This matches unencrypted messages where `content.body` contains the owner's display name in
    /// that room.
    ContainsDisplayName,

    /// This matches the current number of members in the room.
    RoomMemberCount(RoomMemberCountCondition),

    /// This takes into account the current power levels in the room, ensuring the sender of the
    /// event has high enough power to trigger the notification.
    SenderNotificationPermission(SenderNotificationPermissionCondition),

    /// Additional variants may be added in the future and will not be considered breaking changes
    /// to ruma-events.
    #[doc(hidden)]
    __Nonexhaustive,
}

impl Serialize for PushCondition {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match *self {
            PushCondition::EventMatch(ref condition) => condition.serialize(serializer),
            PushCondition::ContainsDisplayName => {
                let mut state = serializer.serialize_struct("ContainsDisplayNameCondition", 1)?;

                state.serialize_field("kind", "contains_display_name")?;

                state.end()
            }
            PushCondition::RoomMemberCount(ref condition) => condition.serialize(serializer),
            PushCondition::SenderNotificationPermission(ref condition) => {
                condition.serialize(serializer)
            }
            PushCondition::__Nonexhaustive => {
                panic!("__Nonexhaustive enum variant is not intended for use.");
            }
        }
    }
}

impl<'de> Deserialize<'de> for PushCondition {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        let value: Value = Deserialize::deserialize(deserializer)?;

        let kind_value = match value.get("kind") {
            Some(value) => value.clone(),
            None => return Err(D::Error::missing_field("kind")),
        };

        let kind = match kind_value.as_str() {
            Some(kind) => kind,
            None => return Err(D::Error::custom("field `kind` must be a string")),
        };

        match kind {
            "event_match" => {
                let condition = match from_value::<EventMatchCondition>(value) {
                    Ok(condition) => condition,
                    Err(error) => return Err(D::Error::custom(error.to_string())),
                };

                Ok(PushCondition::EventMatch(condition))
            }
            "contains_display_name" => Ok(PushCondition::ContainsDisplayName),
            "room_member_count" => {
                let condition = match from_value::<RoomMemberCountCondition>(value) {
                    Ok(condition) => condition,
                    Err(error) => return Err(D::Error::custom(error.to_string())),
                };

                Ok(PushCondition::RoomMemberCount(condition))
            }
            "sender_notification_permission" => {
                let condition = match from_value::<SenderNotificationPermissionCondition>(value) {
                    Ok(condition) => condition,
                    Err(error) => return Err(D::Error::custom(error.to_string())),
                };

                Ok(PushCondition::SenderNotificationPermission(condition))
            }
            unknown_kind => Err(D::Error::custom(&format!(
                "unknown condition kind `{}`",
                unknown_kind
            ))),
        }
    }
}
/// A push condition that matches a glob pattern match on a field of the event.
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct EventMatchCondition {
    /// The dot-separated field of the event to match.
    pub key: String,

    /// The glob-style pattern to match against.
    ///
    /// Patterns with no special glob characters should be treated as having asterisks prepended and
    /// appended when testing the condition.
    pub pattern: String,
}

impl Serialize for EventMatchCondition {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("EventMatchCondition", 3)?;

        state.serialize_field("key", &self.key)?;
        state.serialize_field("kind", "event_match")?;
        state.serialize_field("pattern", &self.pattern)?;

        state.end()
    }
}

/// A push condition that matches the current number of members in the room.
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct RoomMemberCountCondition {
    /// A decimal integer optionally prefixed by one of `==`, `<`, `>`, `>=` or `<=`.
    ///
    /// A prefix of `<` matches rooms where the member count is strictly less than the given number
    /// and so forth. If no prefix is present, this parameter defaults to `==`.
    pub is: String,
}

impl Serialize for RoomMemberCountCondition {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("RoomMemberCountCondition", 2)?;

        state.serialize_field("is", &self.is)?;
        state.serialize_field("kind", "room_member_count")?;

        state.end()
    }
}

/// A push condition that takes into account the current power levels in the room, ensuring the
/// sender of the event has high enough power to trigger the notification.
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct SenderNotificationPermissionCondition {
    /// The field in the power level event the user needs a minimum power level for.
    ///
    /// Fields must be specified under the `notifications` property in the power level event's
    /// `content`.
    pub key: String,
}

impl Serialize for SenderNotificationPermissionCondition {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("SenderNotificationPermissionCondition", 2)?;

        state.serialize_field("key", &self.key)?;
        state.serialize_field("kind", "sender_notification_permission")?;

        state.end()
    }
}

#[cfg(test)]
mod tests {
    use serde_json::{from_str, to_string};

    use super::{
        Action, EventMatchCondition, PushCondition, PushRulesEvent, RoomMemberCountCondition,
        SenderNotificationPermissionCondition, Tweak,
    };
    use crate::EventResult;

    #[test]
    fn serialize_string_action() {
        assert_eq!(to_string(&Action::Notify).unwrap(), r#""notify""#);
    }

    #[test]
    fn serialize_tweak_sound_action() {
        assert_eq!(
            to_string(&Action::SetTweak(Tweak::Sound {
                value: "default".to_string()
            }))
            .unwrap(),
            r#"{"set_tweak":"sound","value":"default"}"#
        );
    }

    #[test]
    fn serialize_tweak_highlight_action() {
        assert_eq!(
            to_string(&Action::SetTweak(Tweak::Highlight { value: true })).unwrap(),
            r#"{"set_tweak":"highlight","value":true}"#
        );
    }

    #[test]
    fn deserialize_string_action() {
        assert_eq!(from_str::<Action>(r#""notify""#).unwrap(), Action::Notify);
    }

    #[test]
    fn deserialize_tweak_sound_action() {
        assert_eq!(
            from_str::<Action>(r#"{"set_tweak":"sound","value":"default"}"#).unwrap(),
            Action::SetTweak(Tweak::Sound {
                value: "default".to_string()
            })
        );
    }

    #[test]
    fn deserialize_tweak_highlight_action() {
        assert_eq!(
            from_str::<Action>(r#"{"set_tweak":"highlight","value":true}"#).unwrap(),
            Action::SetTweak(Tweak::Highlight { value: true })
        );
    }

    #[test]
    fn deserialize_tweak_highlight_action_with_default_value() {
        assert_eq!(
            from_str::<Action>(r#"{"set_tweak":"highlight"}"#).unwrap(),
            Action::SetTweak(Tweak::Highlight { value: true })
        );
    }

    #[test]
    fn serialize_event_match_condition() {
        assert_eq!(
            to_string(&PushCondition::EventMatch(EventMatchCondition {
                key: "content.msgtype".to_string(),
                pattern: "m.notice".to_string(),
            }))
            .unwrap(),
            r#"{"key":"content.msgtype","kind":"event_match","pattern":"m.notice"}"#
        );
    }

    #[test]
    fn serialize_contains_display_name_condition() {
        assert_eq!(
            to_string(&PushCondition::ContainsDisplayName).unwrap(),
            r#"{"kind":"contains_display_name"}"#
        );
    }

    #[test]
    fn serialize_room_member_count_condition() {
        assert_eq!(
            to_string(&PushCondition::RoomMemberCount(RoomMemberCountCondition {
                is: "2".to_string(),
            }))
            .unwrap(),
            r#"{"is":"2","kind":"room_member_count"}"#
        );
    }

    #[test]
    fn serialize_sender_notification_permission_condition() {
        assert_eq!(
            r#"{"key":"room","kind":"sender_notification_permission"}"#,
            to_string(&PushCondition::SenderNotificationPermission(
                SenderNotificationPermissionCondition {
                    key: "room".to_string(),
                }
            ))
            .unwrap(),
        );
    }

    #[test]
    fn deserialize_event_match_condition() {
        assert_eq!(
            from_str::<PushCondition>(
                r#"{"key":"content.msgtype","kind":"event_match","pattern":"m.notice"}"#
            )
            .unwrap(),
            PushCondition::EventMatch(EventMatchCondition {
                key: "content.msgtype".to_string(),
                pattern: "m.notice".to_string(),
            })
        );
    }

    #[test]
    fn deserialize_contains_display_name_condition() {
        assert_eq!(
            from_str::<PushCondition>(r#"{"kind":"contains_display_name"}"#).unwrap(),
            PushCondition::ContainsDisplayName,
        );
    }

    #[test]
    fn deserialize_room_member_count_condition() {
        assert_eq!(
            from_str::<PushCondition>(r#"{"is":"2","kind":"room_member_count"}"#).unwrap(),
            PushCondition::RoomMemberCount(RoomMemberCountCondition {
                is: "2".to_string(),
            })
        );
    }

    #[test]
    fn deserialize_sender_notification_permission_condition() {
        assert_eq!(
            from_str::<PushCondition>(r#"{"key":"room","kind":"sender_notification_permission"}"#)
                .unwrap(),
            PushCondition::SenderNotificationPermission(SenderNotificationPermissionCondition {
                key: "room".to_string(),
            })
        );
    }

    #[test]
    fn sanity_check() {
        // This is a full example of a push rules event from the specification.
        let json = r#"{
    "content": {
        "global": {
            "content": [
                {
                    "actions": [
                        "notify",
                        {
                            "set_tweak": "sound",
                            "value": "default"
                        },
                        {
                            "set_tweak": "highlight"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "pattern": "alice",
                    "rule_id": ".m.rule.contains_user_name"
                }
            ],
            "override": [
                {
                    "actions": [
                        "dont_notify"
                    ],
                    "conditions": [],
                    "default": true,
                    "enabled": false,
                    "rule_id": ".m.rule.master"
                },
                {
                    "actions": [
                        "dont_notify"
                    ],
                    "conditions": [
                        {
                            "key": "content.msgtype",
                            "kind": "event_match",
                            "pattern": "m.notice"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "rule_id": ".m.rule.suppress_notices"
                }
            ],
            "room": [],
            "sender": [],
            "underride": [
                {
                    "actions": [
                        "notify",
                        {
                            "set_tweak": "sound",
                            "value": "ring"
                        },
                        {
                            "set_tweak": "highlight",
                            "value": false
                        }
                    ],
                    "conditions": [
                        {
                            "key": "type",
                            "kind": "event_match",
                            "pattern": "m.call.invite"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "rule_id": ".m.rule.call"
                },
                {
                    "actions": [
                        "notify",
                        {
                            "set_tweak": "sound",
                            "value": "default"
                        },
                        {
                            "set_tweak": "highlight"
                        }
                    ],
                    "conditions": [
                        {
                            "kind": "contains_display_name"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "rule_id": ".m.rule.contains_display_name"
                },
                {
                    "actions": [
                        "notify",
                        {
                            "set_tweak": "sound",
                            "value": "default"
                        },
                        {
                            "set_tweak": "highlight",
                            "value": false
                        }
                    ],
                    "conditions": [
                        {
                            "is": "2",
                            "kind": "room_member_count"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "rule_id": ".m.rule.room_one_to_one"
                },
                {
                    "actions": [
                        "notify",
                        {
                            "set_tweak": "sound",
                            "value": "default"
                        },
                        {
                            "set_tweak": "highlight",
                            "value": false
                        }
                    ],
                    "conditions": [
                        {
                            "key": "type",
                            "kind": "event_match",
                            "pattern": "m.room.member"
                        },
                        {
                            "key": "content.membership",
                            "kind": "event_match",
                            "pattern": "invite"
                        },
                        {
                            "key": "state_key",
                            "kind": "event_match",
                            "pattern": "@alice:example.com"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "rule_id": ".m.rule.invite_for_me"
                },
                {
                    "actions": [
                        "notify",
                        {
                            "set_tweak": "highlight",
                            "value": false
                        }
                    ],
                    "conditions": [
                        {
                            "key": "type",
                            "kind": "event_match",
                            "pattern": "m.room.member"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "rule_id": ".m.rule.member_event"
                },
                {
                    "actions": [
                        "notify",
                        {
                            "set_tweak": "highlight",
                            "value": false
                        }
                    ],
                    "conditions": [
                        {
                            "key": "type",
                            "kind": "event_match",
                            "pattern": "m.room.message"
                        }
                    ],
                    "default": true,
                    "enabled": true,
                    "rule_id": ".m.rule.message"
                }
            ]
        }
    },
    "type": "m.push_rules"
}"#;
        assert!(serde_json::from_str::<EventResult<PushRulesEvent>>(json)
            .unwrap()
            .into_result()
            .is_ok());
    }
}