@@ -14,9 +14,9 @@ use crate::NotificationSettingsError;
14
14
#[ derive( Clone , Debug ) ]
15
15
pub ( crate ) enum Command {
16
16
/// Set a new `Room` push rule
17
- SetRoomPushRule { room_id : OwnedRoomId , notify : bool } ,
17
+ SetRoomPushRule { room_id : OwnedRoomId , notify : Notify } ,
18
18
/// Set a new `Override` push rule matching a `RoomId`
19
- SetOverridePushRule { rule_id : String , room_id : OwnedRoomId , notify : bool } ,
19
+ SetOverridePushRule { rule_id : String , room_id : OwnedRoomId , notify : Notify } ,
20
20
/// Set a new push rule for a keyword.
21
21
SetKeywordPushRule { keyword : String } ,
22
22
/// Set whether a push rule is enabled
@@ -29,21 +29,13 @@ pub(crate) enum Command {
29
29
SetCustomPushRule { rule : NewPushRule } ,
30
30
}
31
31
32
- fn get_notify_actions ( notify : bool ) -> Vec < Action > {
33
- if notify {
34
- vec ! [ Action :: Notify , Action :: SetTweak ( Tweak :: Sound ( "default" . into( ) ) ) ]
35
- } else {
36
- vec ! [ ]
37
- }
38
- }
39
-
40
32
impl Command {
41
33
/// Tries to create a push rule corresponding to this command
42
34
pub ( crate ) fn to_push_rule ( & self ) -> Result < NewPushRule , NotificationSettingsError > {
43
35
match self {
44
36
Self :: SetRoomPushRule { room_id, notify } => {
45
37
// `Room` push rule for this `room_id`
46
- let new_rule = NewSimplePushRule :: new ( room_id. clone ( ) , get_notify_actions ( * notify) ) ;
38
+ let new_rule = NewSimplePushRule :: new ( room_id. clone ( ) , notify. get_actions ( ) ) ;
47
39
Ok ( NewPushRule :: Room ( new_rule) )
48
40
}
49
41
@@ -55,7 +47,7 @@ impl Command {
55
47
key: "room_id" . to_owned( ) ,
56
48
pattern: room_id. to_string( ) ,
57
49
} ] ,
58
- get_notify_actions ( * notify) ,
50
+ notify. get_actions ( ) ,
59
51
) ;
60
52
Ok ( NewPushRule :: Override ( new_rule) )
61
53
}
@@ -65,7 +57,7 @@ impl Command {
65
57
let new_rule = NewPatternedPushRule :: new (
66
58
keyword. clone ( ) ,
67
59
keyword. clone ( ) ,
68
- get_notify_actions ( true ) ,
60
+ Notify :: All . get_actions ( ) ,
69
61
) ;
70
62
Ok ( NewPushRule :: Content ( new_rule) )
71
63
}
@@ -80,3 +72,28 @@ impl Command {
80
72
}
81
73
}
82
74
}
75
+
76
+ /// Enum describing if and how to deliver a notification.
77
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
78
+ pub ( crate ) enum Notify {
79
+ /// Generate a notification both in-app and remote / push.
80
+ All ,
81
+
82
+ /// Only generate an in-app notification but no remote / push notification.
83
+ #[ cfg( feature = "unstable-msc3768" ) ]
84
+ InAppOnly ,
85
+
86
+ /// Don't notify at all.
87
+ None
88
+ }
89
+
90
+ impl Notify {
91
+ fn get_actions ( & self ) -> Vec < Action > {
92
+ match self {
93
+ Self :: All => vec ! [ Action :: Notify , Action :: SetTweak ( Tweak :: Sound ( "default" . into( ) ) ) ] ,
94
+ #[ cfg( feature = "unstable-msc3768" ) ]
95
+ Self :: InAppOnly => vec ! [ Action :: NotifyInApp ] ,
96
+ Self :: None => vec ! [ ]
97
+ }
98
+ }
99
+ }
0 commit comments