diff --git a/book/src/configuration/servers/README.md b/book/src/configuration/servers/README.md index c54b7a296..ec9f0949c 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 c9bea4a23..b19c6ad05 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())]); @@ -1341,7 +1343,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 77ae33250..d70e559f9 100644 --- a/data/src/config/server.rs +++ b/data/src/config/server.rs @@ -78,6 +78,9 @@ pub struct Server { /// Commands which are executed once connected. #[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( default = "default_who_poll_interval", @@ -168,6 +171,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 +286,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) }