mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Implement Message Carbons.
This commit is contained in:
parent
9d6a43f620
commit
329afabb66
4 changed files with 141 additions and 0 deletions
8
doap.xml
8
doap.xml
|
@ -339,6 +339,14 @@
|
|||
<xmpp:note>only the namespace is included for now</xmpp:note>
|
||||
</xmpp:SupportedXep>
|
||||
</xmpp:supports>
|
||||
<xmpp:supports>
|
||||
<xmpp:SupportedXep>
|
||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0280.html"/>
|
||||
<xmpp:status>complete</xmpp:status>
|
||||
<xmpp:version>0.13.0</xmpp:version>
|
||||
<xmpp:since>NEXT</xmpp:since>
|
||||
</xmpp:SupportedXep>
|
||||
</xmpp:supports>
|
||||
<xmpp:supports>
|
||||
<xmpp:SupportedXep>
|
||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0297.html"/>
|
||||
|
|
127
src/carbons.rs
Normal file
127
src/carbons.rs
Normal file
|
@ -0,0 +1,127 @@
|
|||
// Copyright (c) 2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
||||
//
|
||||
// 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 crate::forwarding::Forwarded;
|
||||
use crate::iq::IqSetPayload;
|
||||
use crate::message::MessagePayload;
|
||||
|
||||
generate_empty_element!(
|
||||
/// Enable carbons for this session.
|
||||
Enable,
|
||||
"enable",
|
||||
CARBONS
|
||||
);
|
||||
|
||||
impl IqSetPayload for Enable {}
|
||||
|
||||
generate_empty_element!(
|
||||
/// Disable a previously-enabled carbons.
|
||||
Disable,
|
||||
"disable",
|
||||
CARBONS
|
||||
);
|
||||
|
||||
impl IqSetPayload for Disable {}
|
||||
|
||||
generate_empty_element!(
|
||||
/// Request the enclosing message to not be copied to other carbons-enabled
|
||||
/// resources of the user.
|
||||
Private,
|
||||
"private",
|
||||
CARBONS
|
||||
);
|
||||
|
||||
impl MessagePayload for Private {}
|
||||
|
||||
generate_element!(
|
||||
/// Wrapper for a message received on another resource.
|
||||
Received, "received", CARBONS,
|
||||
|
||||
children: [
|
||||
/// Wrapper for the enclosed message.
|
||||
forwarded: Required<Forwarded> = ("forwarded", FORWARD) => Forwarded
|
||||
]
|
||||
);
|
||||
|
||||
impl MessagePayload for Received {}
|
||||
|
||||
generate_element!(
|
||||
/// Wrapper for a message sent from another resource.
|
||||
Sent, "sent", CARBONS,
|
||||
|
||||
children: [
|
||||
/// Wrapper for the enclosed message.
|
||||
forwarded: Required<Forwarded> = ("forwarded", FORWARD) => Forwarded
|
||||
]
|
||||
);
|
||||
|
||||
impl MessagePayload for Sent {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use minidom::Element;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
#[test]
|
||||
fn test_size() {
|
||||
assert_size!(Enable, 0);
|
||||
assert_size!(Disable, 0);
|
||||
assert_size!(Private, 0);
|
||||
assert_size!(Received, 212);
|
||||
assert_size!(Sent, 212);
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
#[test]
|
||||
fn test_size() {
|
||||
assert_size!(Enable, 0);
|
||||
assert_size!(Disable, 0);
|
||||
assert_size!(Private, 0);
|
||||
assert_size!(Received, 408);
|
||||
assert_size!(Sent, 408);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_elements() {
|
||||
let elem: Element = "<enable xmlns='urn:xmpp:carbons:2'/>".parse().unwrap();
|
||||
Enable::try_from(elem).unwrap();
|
||||
|
||||
let elem: Element = "<disable xmlns='urn:xmpp:carbons:2'/>".parse().unwrap();
|
||||
Disable::try_from(elem).unwrap();
|
||||
|
||||
let elem: Element = "<private xmlns='urn:xmpp:carbons:2'/>".parse().unwrap();
|
||||
Private::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forwarded_elements() {
|
||||
let elem: Element = "<received xmlns='urn:xmpp:carbons:2'>
|
||||
<forwarded xmlns='urn:xmpp:forward:0'>
|
||||
<message xmlns='jabber:client'
|
||||
to='juliet@capulet.example/balcony'
|
||||
from='romeo@montague.example/home'/>
|
||||
</forwarded>
|
||||
</received>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let received = Received::try_from(elem).unwrap();
|
||||
assert!(received.forwarded.stanza.is_some());
|
||||
|
||||
let elem: Element = "<sent xmlns='urn:xmpp:carbons:2'>
|
||||
<forwarded xmlns='urn:xmpp:forward:0'>
|
||||
<message xmlns='jabber:client'
|
||||
to='juliet@capulet.example/balcony'
|
||||
from='romeo@montague.example/home'/>
|
||||
</forwarded>
|
||||
</sent>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let sent = Sent::try_from(elem).unwrap();
|
||||
assert!(sent.forwarded.stanza.is_some());
|
||||
}
|
||||
}
|
|
@ -149,6 +149,9 @@ pub mod jingle_s5b;
|
|||
/// XEP-0261: Jingle In-Band Bytestreams Transport Method
|
||||
pub mod jingle_ibb;
|
||||
|
||||
/// XEP-0280: Message Carbons
|
||||
pub mod carbons;
|
||||
|
||||
/// XEP-0297: Stanza Forwarding
|
||||
pub mod forwarding;
|
||||
|
||||
|
|
|
@ -138,6 +138,9 @@ pub const JINGLE_IBB: &str = "urn:xmpp:jingle:transports:ibb:1";
|
|||
/// XEP-0277: Microblogging over XMPP
|
||||
pub const MICROBLOG: &str = "urn:xmpp:microblog:0";
|
||||
|
||||
/// XEP-0280: Message Carbons
|
||||
pub const CARBONS: &str = "urn:xmpp:carbons:2";
|
||||
|
||||
/// XEP-0297: Stanza Forwarding
|
||||
pub const FORWARD: &str = "urn:xmpp:forward:0";
|
||||
|
||||
|
|
Loading…
Reference in a new issue