@@ -25,7 +25,7 @@ use chrono::Utc;
25
25
use data:: config:: { self , Config } ;
26
26
use data:: history:: { self , manager:: Broadcast } ;
27
27
use data:: version:: Version ;
28
- use data:: { environment, server, version, Server , Url , User } ;
28
+ use data:: { client :: Notification , environment, server, version, Server , Url , User } ;
29
29
use iced:: widget:: { column, container} ;
30
30
use iced:: { padding, Length , Subscription , Task } ;
31
31
use screen:: { dashboard, help, migration, welcome} ;
@@ -34,6 +34,7 @@ use tokio_stream::wrappers::ReceiverStream;
34
34
35
35
use self :: event:: { events, Event } ;
36
36
use self :: modal:: Modal ;
37
+ use self :: notification:: Notifications ;
37
38
use self :: widget:: Element ;
38
39
use self :: window:: Window ;
39
40
@@ -131,6 +132,7 @@ struct Halloy {
131
132
modal : Option < Modal > ,
132
133
main_window : Window ,
133
134
pending_logs : Vec < data:: log:: Record > ,
135
+ notifications : Notifications ,
134
136
}
135
137
136
138
impl Halloy {
@@ -194,6 +196,7 @@ impl Halloy {
194
196
modal : None ,
195
197
main_window,
196
198
pending_logs : vec ! [ ] ,
199
+ notifications : Notifications :: new ( ) ,
197
200
} ,
198
201
command,
199
202
)
@@ -432,7 +435,11 @@ impl Halloy {
432
435
. broadcast ( & server, & self . config , sent_time, Broadcast :: Connecting )
433
436
. map ( Message :: Dashboard )
434
437
} else {
435
- notification:: disconnected ( & self . config . notifications , & server) ;
438
+ self . notifications . notify (
439
+ & self . config . notifications ,
440
+ & Notification :: Disconnected ,
441
+ Some ( & server) ,
442
+ ) ;
436
443
437
444
dashboard
438
445
. broadcast (
@@ -457,13 +464,21 @@ impl Halloy {
457
464
} ;
458
465
459
466
if is_initial {
460
- notification:: connected ( & self . config . notifications , & server) ;
467
+ self . notifications . notify (
468
+ & self . config . notifications ,
469
+ & Notification :: Connected ,
470
+ Some ( & server) ,
471
+ ) ;
461
472
462
473
dashboard
463
474
. broadcast ( & server, & self . config , sent_time, Broadcast :: Connected )
464
475
. map ( Message :: Dashboard )
465
476
} else {
466
- notification:: reconnected ( & self . config . notifications , & server) ;
477
+ self . notifications . notify (
478
+ & self . config . notifications ,
479
+ & Notification :: Reconnected ,
480
+ Some ( & server) ,
481
+ ) ;
467
482
468
483
dashboard
469
484
. broadcast ( & server, & self . config , sent_time, Broadcast :: Reconnected )
@@ -689,58 +704,36 @@ impl Halloy {
689
704
}
690
705
}
691
706
692
- match notification {
707
+ match & notification {
693
708
data:: client:: Notification :: DirectMessage ( user) => {
694
- // only send notification if query has unread
695
- // or if window is not focused
696
709
if dashboard. history ( ) . has_unread (
697
710
& history:: Kind :: Query (
698
711
server. clone ( ) ,
699
712
user. nickname ( ) . to_owned ( ) ,
700
713
) ,
701
714
) || !self . main_window . focused
702
715
{
703
- notification :: direct_message (
716
+ self . notifications . notify (
704
717
& self . config . notifications ,
705
- user. nickname ( ) ,
718
+ & notification,
719
+ None :: < Server > ,
706
720
) ;
707
721
}
708
722
}
709
723
data:: client:: Notification :: Highlight {
710
- enabled,
711
- user,
712
- channel,
713
- } => {
714
- if enabled {
715
- notification:: highlight (
716
- & self . config . notifications ,
717
- user. nickname ( ) ,
718
- channel,
719
- ) ;
720
- }
721
- }
722
- data:: client:: Notification :: MonitoredOnline (
723
- targets,
724
- ) => {
725
- targets. into_iter ( ) . for_each ( |target| {
726
- notification:: monitored_online (
727
- & self . config . notifications ,
728
- target. nickname ( ) . to_owned ( ) ,
729
- server. clone ( ) ,
730
- ) ;
731
- } ) ;
724
+ enabled : _,
725
+ user : _,
726
+ channel : _,
732
727
}
733
- data:: client:: Notification :: MonitoredOffline (
734
- targets,
735
- ) => {
736
- targets. into_iter ( ) . for_each ( |target| {
737
- notification:: monitored_offline (
738
- & self . config . notifications ,
739
- target,
740
- server. clone ( ) ,
741
- ) ;
742
- } ) ;
728
+ | data:: client:: Notification :: MonitoredOnline ( _)
729
+ | data:: client:: Notification :: MonitoredOffline ( _) => {
730
+ self . notifications . notify (
731
+ & self . config . notifications ,
732
+ & notification,
733
+ Some ( & server) ,
734
+ ) ;
743
735
}
736
+ _ => { }
744
737
}
745
738
}
746
739
data:: client:: Event :: FileTransferRequest ( request) => {
0 commit comments