iq, message: Wire up MAM to the payloads.

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-19 02:58:35 +01:00
parent 967d4af843
commit d680c31cf9
2 changed files with 18 additions and 0 deletions

View file

@ -21,6 +21,7 @@ use disco::Disco;
use ibb::IBB; use ibb::IBB;
use jingle::Jingle; use jingle::Jingle;
use ping::Ping; use ping::Ping;
use mam::{Query as MamQuery, Fin as MamFin, Prefs as MamPrefs};
/// Lists every known payload of a `<iq/>`. /// Lists every known payload of a `<iq/>`.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -29,6 +30,9 @@ pub enum IqPayload {
IBB(IBB), IBB(IBB),
Jingle(Jingle), Jingle(Jingle),
Ping(Ping), Ping(Ping),
MamQuery(MamQuery),
MamFin(MamFin),
MamPrefs(MamPrefs),
Unknown(Element), Unknown(Element),
} }
@ -52,6 +56,11 @@ impl<'a> TryFrom<&'a Element> for IqPayload {
// XEP-0199 // XEP-0199
("ping", ns::PING) => IqPayload::Ping(Ping::try_from(elem)?), ("ping", ns::PING) => IqPayload::Ping(Ping::try_from(elem)?),
// XEP-0313
("query", ns::MAM) => IqPayload::MamQuery(MamQuery::try_from(elem)?),
("fin", ns::MAM) => IqPayload::MamFin(MamFin::try_from(elem)?),
("prefs", ns::MAM) => IqPayload::MamPrefs(MamPrefs::try_from(elem)?),
_ => IqPayload::Unknown(elem.clone()), _ => IqPayload::Unknown(elem.clone()),
}) })
} }
@ -166,6 +175,9 @@ impl<'a> Into<Element> for &'a IqPayload {
IqPayload::IBB(ref ibb) => ibb.into(), IqPayload::IBB(ref ibb) => ibb.into(),
IqPayload::Jingle(ref jingle) => jingle.into(), IqPayload::Jingle(ref jingle) => jingle.into(),
IqPayload::Ping(ref ping) => ping.into(), IqPayload::Ping(ref ping) => ping.into(),
IqPayload::MamQuery(ref query) => query.into(),
IqPayload::MamFin(ref fin) => fin.into(),
IqPayload::MamPrefs(ref prefs) => prefs.into(),
IqPayload::Unknown(ref elem) => elem.clone(), IqPayload::Unknown(ref elem) => elem.clone(),
} }

View file

@ -24,6 +24,7 @@ use attention::Attention;
use message_correct::Replace; use message_correct::Replace;
use eme::ExplicitMessageEncryption; use eme::ExplicitMessageEncryption;
use stanza_id::StanzaId; use stanza_id::StanzaId;
use mam::Result_ as MamResult;
/// Lists every known payload of a `<message/>`. /// Lists every known payload of a `<message/>`.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -36,6 +37,7 @@ pub enum MessagePayload {
MessageCorrect(Replace), MessageCorrect(Replace),
ExplicitMessageEncryption(ExplicitMessageEncryption), ExplicitMessageEncryption(ExplicitMessageEncryption),
StanzaId(StanzaId), StanzaId(StanzaId),
MamResult(MamResult),
Unknown(Element), Unknown(Element),
} }
@ -67,6 +69,9 @@ impl<'a> TryFrom<&'a Element> for MessagePayload {
// XEP-0308 // XEP-0308
("replace", ns::MESSAGE_CORRECT) => MessagePayload::MessageCorrect(Replace::try_from(elem)?), ("replace", ns::MESSAGE_CORRECT) => MessagePayload::MessageCorrect(Replace::try_from(elem)?),
// XEP-0313
("result", ns::MAM) => MessagePayload::MamResult(MamResult::try_from(elem)?),
// XEP-0359 // XEP-0359
("stanza-id", ns::SID) => MessagePayload::StanzaId(StanzaId::try_from(elem)?), ("stanza-id", ns::SID) => MessagePayload::StanzaId(StanzaId::try_from(elem)?),
@ -89,6 +94,7 @@ impl<'a> Into<Element> for &'a MessagePayload {
MessagePayload::MessageCorrect(ref replace) => replace.into(), MessagePayload::MessageCorrect(ref replace) => replace.into(),
MessagePayload::ExplicitMessageEncryption(ref eme) => eme.into(), MessagePayload::ExplicitMessageEncryption(ref eme) => eme.into(),
MessagePayload::StanzaId(ref stanza_id) => stanza_id.into(), MessagePayload::StanzaId(ref stanza_id) => stanza_id.into(),
MessagePayload::MamResult(ref result) => result.into(),
MessagePayload::Unknown(ref elem) => elem.clone(), MessagePayload::Unknown(ref elem) => elem.clone(),
} }