From 5069479787ea4cbbf5345af3c053de64e1d66b24 Mon Sep 17 00:00:00 2001 From: Andrew Baldwin Date: Mon, 16 Sep 2024 13:58:42 -0700 Subject: [PATCH] Support for [message-ids](https://ircv3.net/specs/extensions/message-ids). --- CHANGELOG.md | 1 + README.md | 1 + book/src/README.md | 1 + data/src/input.rs | 2 ++ data/src/message.rs | 16 ++++++++++++++++ data/src/message/broadcast.rs | 1 + 6 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65e38c3ce..662b448f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +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` Fixed: diff --git a/README.md b/README.md index bce5fd5ae..04ea3d52e 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Halloy is also available from [Flathub](https://flathub.org/apps/org.squidowl.ha * [labeled-response](https://ircv3.net/specs/extensions/labeled-response) * [message-tags](https://ircv3.net/specs/extensions/message-tags) * [Monitor](https://ircv3.net/specs/extensions/monitor) + * [msgid](https://ircv3.net/specs/extensions/message-ids) * [multi-prefix](https://ircv3.net/specs/extensions/multi-prefix) * [sasl-3.1](https://ircv3.net/specs/extensions/sasl-3.1) * [server-time](https://ircv3.net/specs/extensions/server-time) diff --git a/book/src/README.md b/book/src/README.md index f88a05f85..69f4387fc 100644 --- a/book/src/README.md +++ b/book/src/README.md @@ -18,6 +18,7 @@ * [labeled-response](https://ircv3.net/specs/extensions/labeled-response) * [message-tags](https://ircv3.net/specs/extensions/message-tags) * [Monitor](https://ircv3.net/specs/extensions/monitor) + * [msgid](https://ircv3.net/specs/extensions/message-ids) * [multi-prefix](https://ircv3.net/specs/extensions/multi-prefix) * [sasl-3.1](https://ircv3.net/specs/extensions/sasl-3.1) * [server-time](https://ircv3.net/specs/extensions/server-time) diff --git a/data/src/input.rs b/data/src/input.rs index e7d48f7c0..e718271d2 100644 --- a/data/src/input.rs +++ b/data/src/input.rs @@ -96,6 +96,7 @@ impl Input { direction: message::Direction::Sent, target, content: message::parse_fragments(text.clone(), channel_users), + id: None, }) .collect(), ), @@ -105,6 +106,7 @@ impl Input { direction: message::Direction::Sent, target: to_target(&target, message::Source::Action)?, content: message::action_text(user.nickname(), Some(&action)), + id: None, }]), _ => None, } diff --git a/data/src/message.rs b/data/src/message.rs index 66a46c86c..b85e3dae6 100644 --- a/data/src/message.rs +++ b/data/src/message.rs @@ -148,6 +148,7 @@ pub struct Message { pub direction: Direction, pub target: Target, pub content: Content, + pub id: Option, } impl Message { @@ -175,6 +176,7 @@ impl Message { channel_users: impl Fn(&str) -> &'a [User], ) -> Option { let server_time = server_time(&encoded); + let id = message_id(&encoded); let content = content( &encoded, &our_nick, @@ -190,6 +192,7 @@ impl Message { direction: Direction::Received, target, content, + id, }) } @@ -203,6 +206,7 @@ impl Message { source: Source::Action, }, content: plain(format!("{from} wants to send you \"{filename}\"")), + id: None, } } @@ -216,6 +220,7 @@ impl Message { source: Source::Action, }, content: plain(format!("offering to send {to} \"{filename}\"")), + id: None, } } @@ -276,6 +281,7 @@ impl<'de> Deserialize<'de> for Message { content: Option, // Old field before we had fragments text: Option, + id: Option, } let Data { @@ -285,6 +291,7 @@ impl<'de> Deserialize<'de> for Message { target, content, text, + id, } = Data::deserialize(deserializer)?; let content = if let Some(content) = content { @@ -303,6 +310,7 @@ impl<'de> Deserialize<'de> for Message { direction, target, content, + id, }) } } @@ -692,6 +700,14 @@ fn target( } } +pub fn message_id(message: &Encoded) -> Option { + message + .tags + .iter() + .find(|tag| &tag.key == "msgid") + .and_then(|tag| tag.value.clone()) +} + pub fn server_time(message: &Encoded) -> DateTime { message .tags diff --git a/data/src/message/broadcast.rs b/data/src/message/broadcast.rs index c4a156133..3269ca991 100644 --- a/data/src/message/broadcast.rs +++ b/data/src/message/broadcast.rs @@ -27,6 +27,7 @@ fn expand( direction: Direction::Received, target, content, + id: None, } };