@@ -14,9 +14,9 @@ use crate::NotificationSettingsError;
1414#[ derive( Clone , Debug ) ]
1515pub ( crate ) enum Command {
1616 /// Set a new `Room` push rule
17- SetRoomPushRule { room_id : OwnedRoomId , notify : bool } ,
17+ SetRoomPushRule { room_id : OwnedRoomId , notify : Notify } ,
1818 /// 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 } ,
2020 /// Set a new push rule for a keyword.
2121 SetKeywordPushRule { keyword : String } ,
2222 /// Set whether a push rule is enabled
@@ -29,21 +29,13 @@ pub(crate) enum Command {
2929 SetCustomPushRule { rule : NewPushRule } ,
3030}
3131
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-
4032impl Command {
4133 /// Tries to create a push rule corresponding to this command
4234 pub ( crate ) fn to_push_rule ( & self ) -> Result < NewPushRule , NotificationSettingsError > {
4335 match self {
4436 Self :: SetRoomPushRule { room_id, notify } => {
4537 // `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 ( ) ) ;
4739 Ok ( NewPushRule :: Room ( new_rule) )
4840 }
4941
@@ -55,7 +47,7 @@ impl Command {
5547 key: "room_id" . to_owned( ) ,
5648 pattern: room_id. to_string( ) ,
5749 } ] ,
58- get_notify_actions ( * notify) ,
50+ notify. get_actions ( ) ,
5951 ) ;
6052 Ok ( NewPushRule :: Override ( new_rule) )
6153 }
@@ -65,7 +57,7 @@ impl Command {
6557 let new_rule = NewPatternedPushRule :: new (
6658 keyword. clone ( ) ,
6759 keyword. clone ( ) ,
68- get_notify_actions ( true ) ,
60+ Notify :: All . get_actions ( ) ,
6961 ) ;
7062 Ok ( NewPushRule :: Content ( new_rule) )
7163 }
@@ -80,3 +72,28 @@ impl Command {
8072 }
8173 }
8274}
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