Skip to content

Commit a9fa38b

Browse files
authored
Merge pull request #665 from englut/main
Timeout delay for notifications
2 parents cc44a9a + 1c1899d commit a9fa38b

File tree

8 files changed

+192
-101
lines changed

8 files changed

+192
-101
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Added:
55
- Ability to disable dimming of away usernames. See [buffer configuartion](https://halloy.squidowl.org/configuration/buffer/away.html).
66
- Enable support for IRCv3 `chathistory`
77
- Highlight notifications for `/me` actions
8+
- Timeout delay for notifications
89

910
# 2024.14 (2024-10-29)
1011

book/src/configuration/notifications.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Following notifications are available:
1919
| `disconnected` | Triggered when a server disconnects |
2020
| `file_transfer_request` | Triggered when a file transfer request is received |
2121
| `highlight` | Triggered when you were highlighted in a buffer |
22+
| `monitored_online` | Triggered when a user you're monitoring is online |
23+
| `monitored_offline` | Triggered when a user you're monitoring is offline |
2224
| `reconnected` | Triggered when a server reconnects |
2325

2426

@@ -38,4 +40,12 @@ Notification should trigger a OS toast.
3840

3941
- **type**: boolean
4042
- **values**: `true`, `false`
41-
- **default**: `false`
43+
- **default**: `false`
44+
45+
## `delay`
46+
47+
Delay in milliseconds before triggering the next notification.
48+
49+
- **type**: integer
50+
- **values**: `0` or greater
51+
- **default**: `500`

data/src/client.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ pub enum State {
4646
Ready(Client),
4747
}
4848

49-
#[derive(Debug)]
49+
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
5050
pub enum Notification {
51+
Connected,
52+
Disconnected,
53+
Reconnected,
5154
DirectMessage(User),
5255
Highlight {
5356
enabled: bool,
5457
user: User,
5558
channel: String,
5659
},
60+
FileTransferRequest(Nick),
5761
MonitoredOnline(Vec<User>),
5862
MonitoredOffline(Vec<Nick>),
5963
}

data/src/config/notification.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ pub struct Notification<T = String> {
99
#[serde(default)]
1010
pub show_toast: bool,
1111
pub sound: Option<T>,
12+
pub delay: Option<u64>,
1213
}
1314

1415
impl<T> Default for Notification<T> {
1516
fn default() -> Self {
1617
Self {
1718
show_toast: false,
1819
sound: None,
20+
delay: Some(500),
1921
}
2022
}
2123
}
@@ -61,6 +63,7 @@ impl Notifications {
6163
Ok(Notification {
6264
show_toast: notification.show_toast,
6365
sound: notification.sound.as_deref().map(Sound::load).transpose()?,
66+
delay: notification.delay,
6467
})
6568
};
6669

irc/proto/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ macro_rules! command {
104104
mod tests {
105105
use super::*;
106106

107-
108107
// Reference: https://defs.ircdocs.horse/defs/chanmembers
109108
const CHANNEL_MEMBERSHIP_PREFIXES: &[char] = &['~', '&', '!', '@', '%', '+'];
110109

src/main.rs

+34-41
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use chrono::Utc;
2525
use data::config::{self, Config};
2626
use data::history::{self, manager::Broadcast};
2727
use data::version::Version;
28-
use data::{environment, server, version, Server, Url, User};
28+
use data::{client::Notification, environment, server, version, Server, Url, User};
2929
use iced::widget::{column, container};
3030
use iced::{padding, Length, Subscription, Task};
3131
use screen::{dashboard, help, migration, welcome};
@@ -34,6 +34,7 @@ use tokio_stream::wrappers::ReceiverStream;
3434

3535
use self::event::{events, Event};
3636
use self::modal::Modal;
37+
use self::notification::Notifications;
3738
use self::widget::Element;
3839
use self::window::Window;
3940

@@ -131,6 +132,7 @@ struct Halloy {
131132
modal: Option<Modal>,
132133
main_window: Window,
133134
pending_logs: Vec<data::log::Record>,
135+
notifications: Notifications,
134136
}
135137

136138
impl Halloy {
@@ -194,6 +196,7 @@ impl Halloy {
194196
modal: None,
195197
main_window,
196198
pending_logs: vec![],
199+
notifications: Notifications::new(),
197200
},
198201
command,
199202
)
@@ -432,7 +435,11 @@ impl Halloy {
432435
.broadcast(&server, &self.config, sent_time, Broadcast::Connecting)
433436
.map(Message::Dashboard)
434437
} else {
435-
notification::disconnected(&self.config.notifications, &server);
438+
self.notifications.notify(
439+
&self.config.notifications,
440+
&Notification::Disconnected,
441+
Some(&server),
442+
);
436443

437444
dashboard
438445
.broadcast(
@@ -457,13 +464,21 @@ impl Halloy {
457464
};
458465

459466
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+
);
461472

462473
dashboard
463474
.broadcast(&server, &self.config, sent_time, Broadcast::Connected)
464475
.map(Message::Dashboard)
465476
} else {
466-
notification::reconnected(&self.config.notifications, &server);
477+
self.notifications.notify(
478+
&self.config.notifications,
479+
&Notification::Reconnected,
480+
Some(&server),
481+
);
467482

468483
dashboard
469484
.broadcast(&server, &self.config, sent_time, Broadcast::Reconnected)
@@ -689,58 +704,36 @@ impl Halloy {
689704
}
690705
}
691706

692-
match notification {
707+
match &notification {
693708
data::client::Notification::DirectMessage(user) => {
694-
// only send notification if query has unread
695-
// or if window is not focused
696709
if dashboard.history().has_unread(
697710
&history::Kind::Query(
698711
server.clone(),
699712
user.nickname().to_owned(),
700713
),
701714
) || !self.main_window.focused
702715
{
703-
notification::direct_message(
716+
self.notifications.notify(
704717
&self.config.notifications,
705-
user.nickname(),
718+
&notification,
719+
None::<Server>,
706720
);
707721
}
708722
}
709723
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: _,
732727
}
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+
);
743735
}
736+
_ => {}
744737
}
745738
}
746739
data::client::Event::FileTransferRequest(request) => {

0 commit comments

Comments
 (0)