Add XEP-0333 Displayed markers
Add XEP-0333 Displayed markers
This commit is contained in:
parent
e2dcd8ac66
commit
3d38a54389
5 changed files with 111 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
|
|||
* 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<String> to Option<u32>, in accordance with XEP-0167 version
|
||||
|
|
|
|||
|
|
@ -514,6 +514,14 @@
|
|||
<xmpp:since>0.16.0</xmpp:since>
|
||||
</xmpp:SupportedXep>
|
||||
</implements>
|
||||
<implements>
|
||||
<xmpp:SupportedXep>
|
||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0333.html"/>
|
||||
<xmpp:status>complete</xmpp:status>
|
||||
<xmpp:version>1.0.0</xmpp:version>
|
||||
<xmpp:since>NEXT</xmpp:since>
|
||||
</xmpp:SupportedXep>
|
||||
</implements>
|
||||
<implements>
|
||||
<xmpp:SupportedXep>
|
||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0335.html"/>
|
||||
|
|
|
|||
96
parsers/src/displayed_markers.rs
Normal file
96
parsers/src/displayed_markers.rs
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright (c) 2026 Paul Fariello <paul@fariello.eu>
|
||||
//
|
||||
// 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 = "<markable xmlns='urn:xmpp:chat-markers:0'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
Markable::try_from(elem).unwrap();
|
||||
|
||||
let elem: Element = "<displayed xmlns='urn:xmpp:chat-markers:0' id='39K7ZYIp'/>"
|
||||
.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 = "<displayed xmlns='urn:xmpp:chat-markers:0'/>"
|
||||
.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"));
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue