Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… implementation.
  • Loading branch information
andymandias committed Sep 17, 2024
1 parent ad6ccf9 commit c135585
Show file tree
Hide file tree
Showing 10 changed files with 547 additions and 58 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Added:
- Ability to include or exclude channels for server messages (join, part, etc.). See [configuration](https://halloy.squidowl.org/configuration/buffer/server_messages/index.html).
- Ability to color nicknames within channel messages. See [configuration](https://halloy.squidowl.org/configuration/buffer/channel/message.html#nickname_color)
- Ability to define a shell command for loading a server password. See [configuration](https://halloy.squidowl.org/configuration/servers/index.html#password_command)
- Enable support for IRCv3 `msgid`
- Enable support for IRCv3 `msgid` and `read-marker`

Fixed:

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Halloy is also available from [Flathub](https://flathub.org/apps/org.squidowl.ha
* [Monitor](https://ircv3.net/specs/extensions/monitor)
* [msgid](https://ircv3.net/specs/extensions/message-ids)
* [multi-prefix](https://ircv3.net/specs/extensions/multi-prefix)
* [read-marker](https://ircv3.net/specs/extensions/read-marker)
* [sasl-3.1](https://ircv3.net/specs/extensions/sasl-3.1)
* [server-time](https://ircv3.net/specs/extensions/server-time)
* [userhost-in-names](https://ircv3.net/specs/extensions/userhost-in-names)
Expand Down
1 change: 1 addition & 0 deletions book/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Monitor](https://ircv3.net/specs/extensions/monitor)
* [msgid](https://ircv3.net/specs/extensions/message-ids)
* [multi-prefix](https://ircv3.net/specs/extensions/multi-prefix)
* [read-marker](https://ircv3.net/specs/extensions/read-marker)
* [sasl-3.1](https://ircv3.net/specs/extensions/sasl-3.1)
* [server-time](https://ircv3.net/specs/extensions/server-time)
* [userhost-in-names](https://ircv3.net/specs/extensions/userhost-in-names)
Expand Down
48 changes: 48 additions & 0 deletions data/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt;
use std::time::{Duration, Instant};

use crate::history::read_marker_to_string;
use crate::message::server_time;
use crate::time::Posix;
use crate::user::{Nick, NickRef};
Expand Down Expand Up @@ -79,6 +80,8 @@ pub enum Event {
Broadcast(Broadcast),
Notification(message::Encoded, Nick, Notification),
FileTransferRequest(file_transfer::ReceiveRequest),
LoadReadMarker(String),
UpdateReadMarker(String, Option<DateTime<Utc>>),
}

pub struct Client {
Expand All @@ -99,6 +102,7 @@ pub struct Client {
supports_away_notify: bool,
supports_account_notify: bool,
supports_extended_join: bool,
supports_read_marker: bool,
highlight_blackout: HighlightBlackout,
registration_required_channels: Vec<String>,
isupport: HashMap<isupport::Kind, isupport::Parameter>,
Expand Down Expand Up @@ -151,6 +155,7 @@ impl Client {
supports_away_notify: false,
supports_account_notify: false,
supports_extended_join: false,
supports_read_marker: false,
highlight_blackout: HighlightBlackout::Blackout(Instant::now()),
registration_required_channels: vec![],
isupport: HashMap::new(),
Expand Down Expand Up @@ -367,6 +372,9 @@ impl Client {
if contains("multi-prefix") {
requested.push("multi-prefix");
}
if contains("draft/read-marker") {
requested.push("draft/read-marker");
}

if !requested.is_empty() {
// Request
Expand Down Expand Up @@ -399,6 +407,9 @@ impl Client {
if caps.contains(&"extended-join") {
self.supports_extended_join = true;
}
if caps.contains(&"draft/read-marker") {
self.supports_read_marker = true;
}

let supports_sasl = caps.iter().any(|cap| cap.contains("sasl"));

Expand Down Expand Up @@ -479,6 +490,9 @@ impl Client {
if newly_contains("multi-prefix") {
requested.push("multi-prefix");
}
if newly_contains("draft/read-marker") {
requested.push("draft/read-marker");
}

if !requested.is_empty() {
// Request
Expand Down Expand Up @@ -506,6 +520,9 @@ impl Client {
if del_caps.contains(&"extended-join") {
self.supports_extended_join = false;
}
if del_caps.contains(&"draft/read-marker") {
self.supports_read_marker = false;
}

self.listed_caps
.retain(|cap| !del_caps.iter().any(|del_cap| del_cap == cap));
Expand Down Expand Up @@ -1225,12 +1242,32 @@ impl Client {
Command::Numeric(RPL_ENDOFMONLIST, _) => {
return None;
}
Command::MARKREAD(target, Some(timestamp)) => {
let timestamp = timestamp.strip_prefix("timestamp=").and_then(|timestamp| {
DateTime::parse_from_rfc3339(timestamp)
.ok()
.map(|dt| dt.with_timezone(&Utc))
});
return Some(vec![Event::UpdateReadMarker(target.clone(), timestamp)]);
}
_ => {}
}

Some(vec![Event::Single(message, self.nickname().to_owned())])
}

pub fn send_markread(&mut self, target: &str, read_marker: Option<DateTime<Utc>>) {
if self.supports_read_marker {
if let Some(read_marker) = read_marker {
let _ = self.handle.try_send(command!(
"MARKREAD",
target.to_string(),
format!("timestamp={}", read_marker_to_string(&Some(read_marker))),
));
}
}
}

fn sync(&mut self) {
self.channels = self.chanmap.keys().cloned().collect();
self.users = self
Expand Down Expand Up @@ -1430,6 +1467,17 @@ impl Map {
}
}

pub fn send_markread(
&mut self,
server: &Server,
target: &str,
read_marker: Option<DateTime<Utc>>,
) {
if let Some(client) = self.client_mut(server) {
client.send_markread(target, read_marker);
}
}

pub fn join(&mut self, server: &Server, channels: &[String]) {
if let Some(client) = self.client_mut(server) {
client.join(channels);
Expand Down
Loading

0 comments on commit c135585

Please sign in to comment.