message: Wire up stanza_error.

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-01 01:04:15 +01:00
parent 3dd0eb3a9b
commit 42abbe2927

View file

@ -16,6 +16,7 @@ use error::Error;
use ns; use ns;
use body; use body;
use stanza_error;
use chatstates; use chatstates;
use receipts; use receipts;
use delay; use delay;
@ -27,6 +28,7 @@ use eme;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum MessagePayload { pub enum MessagePayload {
Body(body::Body), Body(body::Body),
StanzaError(stanza_error::StanzaError),
ChatState(chatstates::ChatState), ChatState(chatstates::ChatState),
Receipt(receipts::Receipt), Receipt(receipts::Receipt),
Delay(delay::Delay), Delay(delay::Delay),
@ -111,6 +113,8 @@ pub fn parse_message(root: &Element) -> Result<Message, Error> {
for elem in root.children() { for elem in root.children() {
let payload = if let Ok(body) = body::parse_body(elem) { let payload = if let Ok(body) = body::parse_body(elem) {
Some(MessagePayload::Body(body)) Some(MessagePayload::Body(body))
} else if let Ok(stanza_error) = stanza_error::parse_stanza_error(elem) {
Some(MessagePayload::StanzaError(stanza_error))
} else if let Ok(chatstate) = chatstates::parse_chatstate(elem) { } else if let Ok(chatstate) = chatstates::parse_chatstate(elem) {
Some(MessagePayload::ChatState(chatstate)) Some(MessagePayload::ChatState(chatstate))
} else if let Ok(receipt) = receipts::parse_receipt(elem) { } else if let Ok(receipt) = receipts::parse_receipt(elem) {
@ -143,6 +147,7 @@ pub fn parse_message(root: &Element) -> Result<Message, Error> {
pub fn serialise_payload(payload: &MessagePayload) -> Element { pub fn serialise_payload(payload: &MessagePayload) -> Element {
match *payload { match *payload {
MessagePayload::Body(ref body) => body::serialise(body), MessagePayload::Body(ref body) => body::serialise(body),
MessagePayload::StanzaError(ref stanza_error) => stanza_error::serialise(stanza_error),
MessagePayload::Attention(ref attention) => attention::serialise(attention), MessagePayload::Attention(ref attention) => attention::serialise(attention),
MessagePayload::ChatState(ref chatstate) => chatstates::serialise(chatstate), MessagePayload::ChatState(ref chatstate) => chatstates::serialise(chatstate),
MessagePayload::Receipt(ref receipt) => receipts::serialise(receipt), MessagePayload::Receipt(ref receipt) => receipts::serialise(receipt),