From ce149b8966418d67a1b5402c0e04956df4187e94 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Fri, 27 Sep 2024 20:47:05 +0200 Subject: [PATCH 1/3] Ability to disable who polling --- book/src/configuration/servers/README.md | 8 ++++++++ data/src/client.rs | 4 +++- data/src/config/server.rs | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/book/src/configuration/servers/README.md b/book/src/configuration/servers/README.md index c54b7a29..ec9f0949 100644 --- a/book/src/configuration/servers/README.md +++ b/book/src/configuration/servers/README.md @@ -220,6 +220,14 @@ Example. `["/msg NickServ IDENTIFY foo bar"]`. - **type**: array of string - **values**: array of any strings - **default**: not set + +## `who_poll_enabled` + +Whether or not to WHO polling is enabled. + +- **type**: boolean +- **values**: `true`, `false` +- **default**: `true` ## `who_poll_interval` diff --git a/data/src/client.rs b/data/src/client.rs index c9bea4a2..febb2e4c 100644 --- a/data/src/client.rs +++ b/data/src/client.rs @@ -1341,7 +1341,9 @@ impl Client { } let request = match state.last_who { - Some(WhoStatus::Done(last)) if !self.supports_away_notify => { + Some(WhoStatus::Done(last)) + if !self.supports_away_notify && self.config.who_poll_enabled => + { (now.duration_since(last) >= self.config.who_poll_interval) .then_some(Request::Poll) } diff --git a/data/src/config/server.rs b/data/src/config/server.rs index 77ae3325..5f1bbd41 100644 --- a/data/src/config/server.rs +++ b/data/src/config/server.rs @@ -78,6 +78,8 @@ pub struct Server { /// Commands which are executed once connected. #[serde(default)] pub on_connect: Vec, + /// Enable WHO polling. Defaults to `true`. + pub who_poll_enabled: bool, /// WHO poll interval for servers without away-notify. #[serde( default = "default_who_poll_interval", @@ -168,6 +170,7 @@ impl Default for Server { root_cert_path: Default::default(), sasl: Default::default(), on_connect: Default::default(), + who_poll_enabled: default_who_poll_enabled(), who_poll_interval: default_who_poll_interval(), who_retry_interval: default_who_retry_interval(), monitor: Default::default(), @@ -282,6 +285,10 @@ fn default_ghost_sequence() -> Vec { vec!["REGAIN".into()] } +fn default_who_poll_enabled() -> bool { + true +} + fn default_who_poll_interval() -> Duration { Duration::from_secs(180) } From 7ff263c95c34ba8dd5cb2691f38e5e362ffdafc4 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Fri, 27 Sep 2024 23:40:01 +0200 Subject: [PATCH 2/3] Only poll who if who is enabled --- data/src/client.rs | 48 ++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/data/src/client.rs b/data/src/client.rs index febb2e4c..b19c6ad0 100644 --- a/data/src/client.rs +++ b/data/src/client.rs @@ -836,31 +836,33 @@ impl Client { if user.nickname() == self.nickname() { self.chanmap.insert(channel.clone(), Channel::default()); - if let Some(state) = self.chanmap.get_mut(channel) { - // Sends WHO to get away state on users. - if self.isupport.contains_key(&isupport::Kind::WHOX) { - let fields = if self.supports_account_notify { - "tcnfa" + // Sends WHO to get away state on users if WHO poll is enabled. + if self.config.who_poll_enabled { + if let Some(state) = self.chanmap.get_mut(channel) { + if self.isupport.contains_key(&isupport::Kind::WHOX) { + let fields = if self.supports_account_notify { + "tcnfa" + } else { + "tcnf" + }; + + let _ = self.handle.try_send(command!( + "WHO", + channel, + fields, + isupport::WHO_POLL_TOKEN.to_owned() + )); + + state.last_who = Some(WhoStatus::Requested( + Instant::now(), + Some(isupport::WHO_POLL_TOKEN), + )); } else { - "tcnf" - }; - - let _ = self.handle.try_send(command!( - "WHO", - channel, - fields, - isupport::WHO_POLL_TOKEN.to_owned() - )); - - state.last_who = Some(WhoStatus::Requested( - Instant::now(), - Some(isupport::WHO_POLL_TOKEN), - )); - } else { - let _ = self.handle.try_send(command!("WHO", channel)); - state.last_who = Some(WhoStatus::Requested(Instant::now(), None)); + let _ = self.handle.try_send(command!("WHO", channel)); + state.last_who = Some(WhoStatus::Requested(Instant::now(), None)); + } + log::debug!("[{}] {channel} - WHO requested", self.server); } - log::debug!("[{}] {channel} - WHO requested", self.server); } return Some(vec![Event::JoinedChannel(channel.clone())]); From 9439e36042b2c60746d9c35440c5479e4299d0d8 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Fri, 27 Sep 2024 23:43:07 +0200 Subject: [PATCH 3/3] Add default serde value --- data/src/config/server.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/data/src/config/server.rs b/data/src/config/server.rs index 5f1bbd41..d70e559f 100644 --- a/data/src/config/server.rs +++ b/data/src/config/server.rs @@ -79,6 +79,7 @@ pub struct Server { #[serde(default)] pub on_connect: Vec, /// Enable WHO polling. Defaults to `true`. + #[serde(default = "default_who_poll_enabled")] pub who_poll_enabled: bool, /// WHO poll interval for servers without away-notify. #[serde(