Skip to content

Commit

Permalink
Merge pull request #599 from squidowl/disable-who-polling
Browse files Browse the repository at this point in the history
Ability to disable who polling
  • Loading branch information
casperstorm authored Sep 29, 2024
2 parents 9f90cb8 + 9439e36 commit 020f316
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
8 changes: 8 additions & 0 deletions book/src/configuration/servers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
52 changes: 28 additions & 24 deletions data/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())]);
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions data/src/config/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ pub struct Server {
/// Commands which are executed once connected.
#[serde(default)]
pub on_connect: Vec<String>,
/// 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",
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -282,6 +286,10 @@ fn default_ghost_sequence() -> Vec<String> {
vec!["REGAIN".into()]
}

fn default_who_poll_enabled() -> bool {
true
}

fn default_who_poll_interval() -> Duration {
Duration::from_secs(180)
}
Expand Down

0 comments on commit 020f316

Please sign in to comment.