From 3d38a5438993ba2f57aac992d67da8ebbfddc680 Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Fri, 8 May 2026 13:57:14 +0200 Subject: [PATCH] Add XEP-0333 Displayed markers Add XEP-0333 Displayed markers --- parsers/ChangeLog | 1 + parsers/doap.xml | 8 +++ parsers/src/displayed_markers.rs | 96 ++++++++++++++++++++++++++++++++ parsers/src/lib.rs | 3 + parsers/src/ns.rs | 3 + 5 files changed, 111 insertions(+) create mode 100644 parsers/src/displayed_markers.rs diff --git a/parsers/ChangeLog b/parsers/ChangeLog index 89a4c449..b3e6e95b 100644 --- a/parsers/ChangeLog +++ b/parsers/ChangeLog @@ -3,6 +3,7 @@ XXXX-YY-ZZ RELEASER * New parsers/serialisers: - Client Access Management (XEP-0494) (!641) - Jingle Content Category (XEP-0507) + - Displayed markers (XEP-0333) (!669) * Breaking - The type of jingle_rtp::Description::ssrc has been changed from Option to Option, in accordance with XEP-0167 version diff --git a/parsers/doap.xml b/parsers/doap.xml index c9af1b48..fe9d294f 100644 --- a/parsers/doap.xml +++ b/parsers/doap.xml @@ -514,6 +514,14 @@ 0.16.0 + + + + complete + 1.0.0 + NEXT + + diff --git a/parsers/src/displayed_markers.rs b/parsers/src/displayed_markers.rs new file mode 100644 index 00000000..a826a174 --- /dev/null +++ b/parsers/src/displayed_markers.rs @@ -0,0 +1,96 @@ +// Copyright (c) 2026 Paul Fariello +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +use xso::{AsXml, FromXml}; + +use crate::message::{Id, MessagePayload}; +use crate::ns; + +/// Request to know if the recipient has displayed a message. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::DISPLAYED_MARKERS, name = "markable")] +pub struct Markable; + +impl MessagePayload for Markable {} + +/// Inform that all messages up to a given message have been displayed. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::DISPLAYED_MARKERS, name = "displayed")] +pub struct Displayed { + /// The 'id' attribute of the displayed message. + #[xml(attribute)] + pub id: Id, +} + +impl MessagePayload for Displayed {} + +#[cfg(test)] +mod tests { + use super::*; + use crate::ns; + use minidom::Element; + use xso::error::{Error, FromElementError}; + use xso::exports::rxml; + + #[cfg(target_pointer_width = "32")] + #[test] + fn test_size() { + assert_size!(Markable, 0); + assert_size!(Displayed, 12); + } + + #[cfg(target_pointer_width = "64")] + #[test] + fn test_size() { + assert_size!(Markable, 0); + assert_size!(Displayed, 24); + } + + #[test] + fn test_simple() { + let elem: Element = "" + .parse() + .unwrap(); + Markable::try_from(elem).unwrap(); + + let elem: Element = "" + .parse() + .unwrap(); + let displayed = Displayed::try_from(elem).unwrap(); + assert_eq!(displayed.id, Id(String::from("39K7ZYIp"))); + } + + #[test] + fn test_missing_id() { + let elem: Element = "" + .parse() + .unwrap(); + let error = Displayed::try_from(elem).unwrap_err(); + let message = match error { + FromElementError::Invalid(Error::Other(string)) => string, + _ => panic!(), + }; + assert_eq!( + message, + "Required attribute field 'id' on Displayed element missing." + ); + } + + #[test] + fn test_serialise() { + let receipt = Markable; + let elem: Element = receipt.into(); + assert!(elem.is("markable", ns::DISPLAYED_MARKERS)); + assert_eq!(elem.attrs().into_iter().count(), 0); + + let receipt = Displayed { + id: Id(String::from("39K7ZYIp")), + }; + let elem: Element = receipt.into(); + assert!(elem.is("displayed", ns::DISPLAYED_MARKERS)); + assert_eq!(elem.attr(rxml::xml_ncname!("id")), Some("39K7ZYIp")); + } +} diff --git a/parsers/src/lib.rs b/parsers/src/lib.rs index a416b342..fc98de01 100644 --- a/parsers/src/lib.rs +++ b/parsers/src/lib.rs @@ -245,6 +245,9 @@ pub mod jingle_dtls_srtp; /// XEP-0328: JID Prep pub mod jid_prep; +/// XEP-0333: Displayed markers +pub mod displayed_markers; + /// XEP-0335: JSON Containers pub mod json_containers; diff --git a/parsers/src/ns.rs b/parsers/src/ns.rs index 964bf6f8..9e323c76 100644 --- a/parsers/src/ns.rs +++ b/parsers/src/ns.rs @@ -232,6 +232,9 @@ pub const JINGLE_DTLS: &str = "urn:xmpp:jingle:apps:dtls:0"; /// XEP-0328: JID Prep pub const JID_PREP: &str = "urn:xmpp:jidprep:0"; +/// XEP-0333: Displayed markers +pub const DISPLAYED_MARKERS: &str = "urn:xmpp:chat-markers:0"; + /// XEP-0335: JSON Containers pub const JSON_CONTAINERS: &str = "urn:xmpp:json:0";