@@ -189,9 +189,46 @@ pub struct SubscriptionRef<'a> {
189189 pub notify : Vec < Accessor < NotifierConfig > > ,
190190}
191191
192+ // Should be always used with `#[serde(flatten)]`
192193#[ derive( Clone , Debug , PartialEq , Deserialize ) ]
193- pub struct Notifications {
194- // Toggles
194+ pub struct NotifierBase {
195+ #[ serde( default ) ]
196+ pub switch : NotificationSwitch ,
197+ #[ serde( default ) ]
198+ pub option : NotificationOption ,
199+ }
200+
201+ serde_impl_default_for ! ( NotifierBase ) ;
202+
203+ impl Overridable for NotifierBase {
204+ type Override = NotifierBaseOverride ;
205+
206+ fn override_into ( self , new : Self :: Override ) -> Self
207+ where
208+ Self : Sized ,
209+ {
210+ Self {
211+ switch : match new. switch {
212+ Some ( switch) => self . switch . override_into ( switch) ,
213+ None => self . switch ,
214+ } ,
215+ option : match new. option {
216+ Some ( option) => self . option . override_into ( option) ,
217+ None => self . option ,
218+ } ,
219+ }
220+ }
221+ }
222+
223+ // Should be always used with `#[serde(flatten)]`
224+ #[ derive( Clone , Debug , PartialEq , Deserialize ) ]
225+ pub struct NotifierBaseOverride {
226+ switch : Option < NotificationSwitchOverride > ,
227+ option : Option < NotificationOptionOverride > ,
228+ }
229+
230+ #[ derive( Clone , Debug , PartialEq , Deserialize ) ]
231+ pub struct NotificationSwitch {
195232 #[ serde( default = "helper::refl_bool::<true>" ) ]
196233 pub live_online : bool ,
197234 #[ serde( default = "helper::refl_bool::<false>" ) ]
@@ -204,16 +241,12 @@ pub struct Notifications {
204241 pub playback : bool ,
205242 #[ serde( default = "helper::refl_bool::<true>" ) ]
206243 pub document : bool ,
207-
208- // Options
209- #[ serde( default = "helper::refl_bool::<false>" ) ]
210- pub author_name : bool ,
211244}
212245
213- serde_impl_default_for ! ( Notifications ) ;
246+ serde_impl_default_for ! ( NotificationSwitch ) ;
214247
215- impl Overridable for Notifications {
216- type Override = NotificationsOverride ;
248+ impl Overridable for NotificationSwitch {
249+ type Override = NotificationSwitchOverride ;
217250
218251 fn override_into ( self , new : Self :: Override ) -> Self
219252 where
@@ -226,19 +259,43 @@ impl Overridable for Notifications {
226259 log : new. log . unwrap_or ( self . log ) ,
227260 playback : new. playback . unwrap_or ( self . playback ) ,
228261 document : new. document . unwrap_or ( self . document ) ,
229- author_name : new. author_name . unwrap_or ( self . author_name ) ,
230262 }
231263 }
232264}
233265
234266#[ derive( Clone , Debug , PartialEq , Deserialize ) ]
235- pub struct NotificationsOverride {
267+ pub struct NotificationSwitchOverride {
236268 pub live_online : Option < bool > ,
237269 pub live_title : Option < bool > ,
238270 pub post : Option < bool > ,
239271 pub log : Option < bool > ,
240272 pub playback : Option < bool > ,
241273 pub document : Option < bool > ,
274+ }
275+
276+ #[ derive( Clone , Debug , PartialEq , Deserialize ) ]
277+ pub struct NotificationOption {
278+ #[ serde( default = "helper::refl_bool::<false>" ) ]
279+ pub author_name : bool ,
280+ }
281+
282+ serde_impl_default_for ! ( NotificationOption ) ;
283+
284+ impl Overridable for NotificationOption {
285+ type Override = NotificationOptionOverride ;
286+
287+ fn override_into ( self , new : Self :: Override ) -> Self
288+ where
289+ Self : Sized ,
290+ {
291+ Self {
292+ author_name : new. author_name . unwrap_or ( self . author_name ) ,
293+ }
294+ }
295+ }
296+
297+ #[ derive( Clone , Debug , PartialEq , Deserialize ) ]
298+ pub struct NotificationOptionOverride {
242299 pub author_name : Option < bool > ,
243300}
244301
@@ -318,7 +375,7 @@ playback = { bililive_recorder = { listen_webhook = { host = "127.0.0.1", port =
318375
319376[notify]
320377meow = { platform = "Telegram", id = 1234, thread_id = 123, token = "xxx" }
321- woof = { platform = "Telegram", id = 5678, thread_id = 900, notifications = { post = false } }
378+ woof = { platform = "Telegram", id = 5678, thread_id = 900, switch = { post = false } }
322379
323380[[subscription.meow]]
324381platform = { name = "bilibili.live", user_id = 123456 }
@@ -385,7 +442,7 @@ notify = ["meow", "woof", { ref = "woof", id = 123 }]
385442 (
386443 "meow" . into( ) ,
387444 Accessor :: new( NotifierConfig :: Telegram ( Accessor :: new( telegram:: notify:: ConfigParams {
388- notifications : Notifications :: default ( ) ,
445+ base : NotifierBase :: default ( ) ,
389446 chat: telegram:: ConfigChat :: Id ( 1234 ) ,
390447 thread_id: Some ( 123 ) ,
391448 token: Some ( telegram:: ConfigToken :: with_raw( "xxx" ) ) ,
@@ -394,14 +451,18 @@ notify = ["meow", "woof", { ref = "woof", id = 123 }]
394451 (
395452 "woof" . into( ) ,
396453 Accessor :: new( NotifierConfig :: Telegram ( Accessor :: new( telegram:: notify:: ConfigParams {
397- notifications: Notifications {
398- live_online: true ,
399- live_title: false ,
400- post: false ,
401- log: true ,
402- playback: true ,
403- document: true ,
404- author_name: false ,
454+ base: NotifierBase {
455+ switch: NotificationSwitch {
456+ live_online: true ,
457+ live_title: false ,
458+ post: false ,
459+ log: true ,
460+ playback: true ,
461+ document: true ,
462+ } ,
463+ option: NotificationOption {
464+ author_name: false ,
465+ }
405466 } ,
406467 chat: telegram:: ConfigChat :: Id ( 5678 ) ,
407468 thread_id: Some ( 900 ) ,
@@ -572,7 +633,7 @@ woof = { platform = "Telegram", id = 5678, thread_id = 456, token = "yyy" }
572633
573634[[subscription.meow]]
574635platform = { name = "bilibili.live", user_id = 123456 }
575- notify = ["meow", { ref = "woof", thread_id = 114 }, { ref = "woof", notifications = { post = false } }]
636+ notify = ["meow", { ref = "woof", thread_id = 114 }, { ref = "woof", switch = { post = false } }]
576637 "# ,
577638 |c| {
578639 let subscriptions = c. unwrap ( ) . subscriptions ( ) . collect :: < Vec < _ > > ( ) ;
@@ -589,25 +650,28 @@ notify = ["meow", { ref = "woof", thread_id = 114 }, { ref = "woof", notificatio
589650 notify: vec![
590651 Accessor :: new( NotifierConfig :: Telegram ( Accessor :: new(
591652 telegram:: notify:: ConfigParams {
592- notifications : Notifications :: default ( ) ,
653+ base : NotifierBase :: default ( ) ,
593654 chat: telegram:: ConfigChat :: Id ( 1234 ) ,
594655 thread_id: Some ( 123 ) ,
595656 token: Some ( telegram:: ConfigToken :: with_raw( "xxx" ) ) ,
596657 }
597658 ) ) ) ,
598659 Accessor :: new( NotifierConfig :: Telegram ( Accessor :: new(
599660 telegram:: notify:: ConfigParams {
600- notifications : Notifications :: default ( ) ,
661+ base : NotifierBase :: default ( ) ,
601662 chat: telegram:: ConfigChat :: Id ( 5678 ) ,
602663 thread_id: Some ( 114 ) ,
603664 token: Some ( telegram:: ConfigToken :: with_raw( "yyy" ) ) ,
604665 }
605666 ) ) ) ,
606667 Accessor :: new( NotifierConfig :: Telegram ( Accessor :: new(
607668 telegram:: notify:: ConfigParams {
608- notifications: Notifications {
609- post: false ,
610- ..Default :: default ( )
669+ base: NotifierBase {
670+ switch: NotificationSwitch {
671+ post: false ,
672+ ..Default :: default ( )
673+ } ,
674+ option: NotificationOption :: default ( )
611675 } ,
612676 chat: telegram:: ConfigChat :: Id ( 5678 ) ,
613677 thread_id: Some ( 456 ) ,
0 commit comments