Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable who polling #599

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
casperstorm marked this conversation as resolved.
Show resolved Hide resolved

- **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
Loading