diff --git a/parsers/src/presence.rs b/parsers/src/presence.rs
index 6d51263de3eff3a87f2537b8f907a7ca956167ec..a45d0b97724944d144749bedb5631c77958b7116 100644
--- a/parsers/src/presence.rs
+++ b/parsers/src/presence.rs
@@ -5,12 +5,13 @@
// 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::{error::Error, AsOptionalXmlText, AsXml, AsXmlText, FromXml, FromXmlText};
+
use crate::ns;
use jid::Jid;
-use minidom::{Element, IntoAttributeValue};
+use minidom::Element;
+use std::borrow::Cow;
use std::collections::BTreeMap;
-use std::str::FromStr;
-use xso::error::{Error, FromElementError};
/// Should be implemented on every known payload of a ``.
pub trait PresencePayload: TryFrom + Into {}
@@ -32,11 +33,9 @@ pub enum Show {
Xa,
}
-impl FromStr for Show {
- type Err = Error;
-
- fn from_str(s: &str) -> Result {
- Ok(match s {
+impl FromXmlText for Show {
+ fn from_xml_text(s: String) -> Result {
+ Ok(match s.as_ref() {
"away" => Show::Away,
"chat" => Show::Chat,
"dnd" => Show::Dnd,
@@ -47,23 +46,26 @@ impl FromStr for Show {
}
}
-impl From for Element {
- fn from(show: Show) -> Element {
- Element::builder("show", ns::DEFAULT_NS)
- .append(match show {
- Show::Away => "away",
- Show::Chat => "chat",
- Show::Dnd => "dnd",
- Show::Xa => "xa",
- })
- .build()
+impl AsXmlText for Show {
+ fn as_xml_text(&self) -> Result, Error> {
+ Ok(Cow::Borrowed(match self {
+ Show::Away => "away",
+ Show::Chat => "chat",
+ Show::Dnd => "dnd",
+ Show::Xa => "xa",
+ }))
}
}
type Lang = String;
type Status = String;
-type Priority = i8;
+/// Priority of this presence. This value can go from -128 to 127, defaults to
+/// 0, and any negative value will prevent this resource from receiving
+/// messages addressed to the bare JID.
+#[derive(FromXml, AsXml, Debug, Default, Clone, PartialEq)]
+#[xml(namespace = ns::DEFAULT_NS, name = "priority")]
+pub struct Priority(#[xml(text)] i8);
/// Accepted values for the 'type' attribute of a presence.
#[derive(Debug, Default, Clone, PartialEq)]
@@ -100,11 +102,9 @@ pub enum Type {
Unsubscribed,
}
-impl FromStr for Type {
- type Err = Error;
-
- fn from_str(s: &str) -> Result {
- Ok(match s {
+impl FromXmlText for Type {
+ fn from_xml_text(s: String) -> Result {
+ Ok(match s.as_ref() {
"error" => Type::Error,
"probe" => Type::Probe,
"subscribe" => Type::Subscribe,
@@ -122,51 +122,60 @@ impl FromStr for Type {
}
}
-impl IntoAttributeValue for Type {
- fn into_attribute_value(self) -> Option {
- Some(
- match self {
- Type::None => return None,
-
- Type::Error => "error",
- Type::Probe => "probe",
- Type::Subscribe => "subscribe",
- Type::Subscribed => "subscribed",
- Type::Unavailable => "unavailable",
- Type::Unsubscribe => "unsubscribe",
- Type::Unsubscribed => "unsubscribed",
- }
- .to_owned(),
- )
+impl AsOptionalXmlText for Type {
+ fn as_optional_xml_text(&self) -> Result