Skip to content

Commit

Permalink
Merge pull request #294 from squidowl/fix/293
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm authored Mar 28, 2024
2 parents c4703e0 + e35d758 commit 858bee0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

Added:

- Configuration to adjust WHO polling for servers without away-notify (see [server configuration](https://halloy.squidowl.org/configuration/servers.html))

Fixed:

- Accept '@' in usernames to support bouncers that use the user@identifier/network convention
Expand Down
4 changes: 4 additions & 0 deletions book/src/configuration/servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ channels = ["#halloy"]
| `dangerously_accept_invalid_certs` | On `true`, all certificate validations are skipped. Defaults to `false`. | `false` |
| `root_cert_path` | The path to the root TLS certificate for this server in PEM format. | `""` |
| `on_connect` | Commands which are executed once connected. Example. `["/msg NickServ IDENTIFY foo bar"]`. | `[]` |
| `who_poll_interval` | WHO poll interval (in seconds) for servers without away-notify. | `180`[^1] |
| `who_retry_interval` | WHO retry interval (in seconds) for servers without away-notify. | `10`[^1] |

[^1]: Limited between `5` and `3600` seconds.

## `[servers.sasl]` Section

Expand Down
11 changes: 5 additions & 6 deletions data/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use crate::time::Posix;
use crate::user::{Nick, NickRef};
use crate::{config, message, mode, Buffer, Server, User};

const WHO_POLL_INTERVAL: Duration = Duration::from_secs(60);
const WHO_RETRY_INTERVAL: Duration = Duration::from_secs(10);
const HIGHLIGHT_BLACKOUT_INTERVAL: Duration = Duration::from_secs(5);

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -764,11 +762,12 @@ impl Client {

let request = match state.last_who {
Some(WhoStatus::Done(last)) if !self.supports_away_notify => {
(now.duration_since(last) >= WHO_POLL_INTERVAL).then_some(Request::Poll)
}
Some(WhoStatus::Requested(requested)) => {
(now.duration_since(requested) >= WHO_RETRY_INTERVAL).then_some(Request::Retry)
(now.duration_since(last) >= self.config.who_poll_interval)
.then_some(Request::Poll)
}
Some(WhoStatus::Requested(requested)) => (now.duration_since(requested)
>= self.config.who_retry_interval)
.then_some(Request::Retry),
_ => None,
};

Expand Down
31 changes: 30 additions & 1 deletion data/src/config/server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::collections::HashMap;
use std::path::PathBuf;
use std::time::Duration;

use irc::connection;
use serde::Deserialize;
use serde::{Deserialize, Deserializer};

#[derive(Debug, Clone, Default, Deserialize)]
pub struct Server {
Expand Down Expand Up @@ -65,6 +66,18 @@ pub struct Server {
/// Commands which are executed once connected.
#[serde(default)]
pub on_connect: Vec<String>,
/// WHO poll interval for servers without away-notify.
#[serde(
default = "default_who_poll_interval",
deserialize_with = "deserialize_duration_from_u64"
)]
pub who_poll_interval: Duration,
/// WHO retry interval for servers without away-notify.
#[serde(
default = "default_who_retry_interval",
deserialize_with = "deserialize_duration_from_u64"
)]
pub who_retry_interval: Duration,
}

impl Server {
Expand Down Expand Up @@ -141,6 +154,14 @@ impl Sasl {
}
}

fn deserialize_duration_from_u64<'de, D>(deserializer: D) -> Result<Duration, D::Error>
where
D: Deserializer<'de>,
{
let seconds: u64 = Deserialize::deserialize(deserializer)?;
Ok(Duration::from_secs(seconds.clamp(5, 3600)))
}

fn default_use_tls() -> bool {
true
}
Expand All @@ -164,3 +185,11 @@ fn default_reconnect_delay() -> u64 {
fn default_ghost_sequence() -> Vec<String> {
vec!["GHOST".into()]
}

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

fn default_who_retry_interval() -> Duration {
Duration::from_secs(10)
}

0 comments on commit 858bee0

Please sign in to comment.