2019-06-26 02:06:38 +02:00
|
|
|
|
// Copyright (c) 2017 Maxime “pep” Buquet <pep@bouah.net>
|
2017-07-20 20:36:13 +01:00
|
|
|
|
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
2017-06-26 23:07:12 +01:00
|
|
|
|
//
|
|
|
|
|
|
// 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/.
|
|
|
|
|
|
|
2023-06-07 16:46:43 +02:00
|
|
|
|
use crate::message::MessagePayload;
|
2018-12-18 15:27:30 +01:00
|
|
|
|
use crate::ns;
|
2022-09-16 19:57:20 +02:00
|
|
|
|
use crate::presence::PresencePayload;
|
2019-10-23 01:32:41 +02:00
|
|
|
|
use crate::util::error::Error;
|
2019-09-25 10:28:44 +02:00
|
|
|
|
use crate::Element;
|
2022-09-10 11:34:45 +02:00
|
|
|
|
|
2019-10-23 01:32:41 +02:00
|
|
|
|
use jid::FullJid;
|
2019-04-12 10:58:42 +02:00
|
|
|
|
use std::convert::TryFrom;
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2017-11-24 05:50:24 +00:00
|
|
|
|
generate_attribute_enum!(
|
|
|
|
|
|
/// Lists all of the possible status codes used in MUC presences.
|
2018-05-14 16:30:28 +02:00
|
|
|
|
Status, "status", MUC_USER, "code", {
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 100: Inform user that any occupant is allowed to see the user's full JID
|
2017-11-24 05:44:58 +00:00
|
|
|
|
NonAnonymousRoom => 100,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 101: Inform user that his or her affiliation changed while not in the room
|
2017-11-24 05:44:58 +00:00
|
|
|
|
AffiliationChange => 101,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 102: Inform occupants that room now shows unavailable members
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigShowsUnavailableMembers => 102,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 103: Inform occupants that room now does not show unavailable members
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigHidesUnavailableMembers => 103,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 104: Inform occupants that a non-privacy-related room configuration change has occurred
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigNonPrivacyRelated => 104,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 110: Inform user that presence refers to itself
|
2017-11-24 05:44:58 +00:00
|
|
|
|
SelfPresence => 110,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 170: Inform occupants that room logging is now enabled
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigRoomLoggingEnabled => 170,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 171: Inform occupants that room logging is now disabled
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigRoomLoggingDisabled => 171,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 172: Inform occupants that the room is now non-anonymous
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigRoomNonAnonymous => 172,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 173: Inform occupants that the room is now semi-anonymous
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigRoomSemiAnonymous => 173,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 201: Inform user that a new room has been created
|
2017-11-24 05:44:58 +00:00
|
|
|
|
RoomHasBeenCreated => 201,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 210: Inform user that service has assigned or modified occupant's roomnick
|
2017-11-24 05:44:58 +00:00
|
|
|
|
AssignedNick => 210,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 12:09:00 +01:00
|
|
|
|
/// 301: Inform user that they have been banned from the room
|
2017-11-24 05:44:58 +00:00
|
|
|
|
Banned => 301,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 11:51:26 +01:00
|
|
|
|
/// 303: Inform all occupants of new room nickname
|
2017-11-24 05:44:58 +00:00
|
|
|
|
NewNick => 303,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 12:09:00 +01:00
|
|
|
|
/// 307: Inform user that they have been kicked from the room
|
2017-11-24 05:44:58 +00:00
|
|
|
|
Kicked => 307,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 12:09:00 +01:00
|
|
|
|
/// 321: Inform user that they are being removed from the room
|
2017-11-24 05:50:24 +00:00
|
|
|
|
/// because of an affiliation change
|
2017-11-24 05:44:58 +00:00
|
|
|
|
RemovalFromRoom => 321,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 12:09:00 +01:00
|
|
|
|
/// 322: Inform user that they are being removed from the room
|
2017-11-24 05:50:24 +00:00
|
|
|
|
/// because the room has been changed to members-only and the
|
|
|
|
|
|
/// user is not a member
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ConfigMembersOnly => 322,
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-17 12:09:00 +01:00
|
|
|
|
/// 332: Inform user that they are being removed from the room
|
2017-11-24 05:50:24 +00:00
|
|
|
|
/// because the MUC service is being shut down
|
2017-11-24 05:44:58 +00:00
|
|
|
|
ServiceShutdown => 332,
|
2022-12-17 12:01:28 +01:00
|
|
|
|
|
2022-12-17 12:09:00 +01:00
|
|
|
|
/// 333: Inform user that they are being removed from the room for technical reasons
|
2022-12-17 12:01:28 +01:00
|
|
|
|
ServiceErrorKick => 333,
|
2017-11-24 05:44:58 +00:00
|
|
|
|
});
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2022-12-27 16:31:58 +01:00
|
|
|
|
/// Optional \<actor/\> element used in \<item/\> elements inside presence stanzas of type
|
2017-06-26 23:07:12 +01:00
|
|
|
|
/// "unavailable" that are sent to users who are kick or banned, as well as within IQs for tracking
|
|
|
|
|
|
/// purposes. -- CHANGELOG 0.17 (2002-10-23)
|
2018-05-28 16:29:51 +02:00
|
|
|
|
///
|
2017-06-26 23:07:12 +01:00
|
|
|
|
/// Possesses a 'jid' and a 'nick' attribute, so that an action can be attributed either to a real
|
|
|
|
|
|
/// JID or to a roomnick. -- CHANGELOG 1.25 (2012-02-08)
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
|
|
pub enum Actor {
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// The full JID associated with this user.
|
2019-06-10 23:17:09 +02:00
|
|
|
|
Jid(FullJid),
|
2018-08-08 20:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
/// The nickname of this user.
|
2017-06-26 23:07:12 +01:00
|
|
|
|
Nick(String),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TryFrom<Element> for Actor {
|
2019-04-12 10:58:42 +02:00
|
|
|
|
type Error = Error;
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
fn try_from(elem: Element) -> Result<Actor, Error> {
|
2018-05-14 16:30:28 +02:00
|
|
|
|
check_self!(elem, "actor", MUC_USER);
|
2018-05-12 17:59:04 +02:00
|
|
|
|
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
|
2018-05-14 16:33:47 +02:00
|
|
|
|
check_no_children!(elem, "actor");
|
2019-06-10 23:17:09 +02:00
|
|
|
|
let jid: Option<FullJid> = get_attr!(elem, "jid", Option);
|
2019-02-24 20:48:19 +01:00
|
|
|
|
let nick = get_attr!(elem, "nick", Option);
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
match (jid, nick) {
|
2019-10-23 01:32:41 +02:00
|
|
|
|
(Some(_), Some(_)) | (None, None) => Err(Error::ParseError(
|
|
|
|
|
|
"Either 'jid' or 'nick' attribute is required.",
|
|
|
|
|
|
)),
|
2017-06-26 23:07:12 +01:00
|
|
|
|
(Some(jid), _) => Ok(Actor::Jid(jid)),
|
|
|
|
|
|
(_, Some(nick)) => Ok(Actor::Nick(nick)),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-20 20:36:13 +01:00
|
|
|
|
impl From<Actor> for Element {
|
|
|
|
|
|
fn from(actor: Actor) -> Element {
|
2020-03-28 13:07:26 +01:00
|
|
|
|
let elem = Element::builder("actor", ns::MUC_USER);
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2017-07-20 20:36:13 +01:00
|
|
|
|
(match actor {
|
2017-07-29 06:28:20 +01:00
|
|
|
|
Actor::Jid(jid) => elem.attr("jid", jid),
|
2017-06-26 23:07:12 +01:00
|
|
|
|
Actor::Nick(nick) => elem.attr("nick", nick),
|
2018-12-18 15:32:05 +01:00
|
|
|
|
})
|
|
|
|
|
|
.build()
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-08 20:22:37 +02:00
|
|
|
|
generate_element!(
|
|
|
|
|
|
/// Used to continue a one-to-one discussion in a room, with more than one
|
|
|
|
|
|
/// participant.
|
|
|
|
|
|
Continue, "continue", MUC_USER,
|
|
|
|
|
|
attributes: [
|
|
|
|
|
|
/// The thread to continue in this room.
|
2019-02-24 20:26:40 +01:00
|
|
|
|
thread: Option<String> = "thread",
|
2018-08-08 20:22:37 +02:00
|
|
|
|
]
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_elem_id!(
|
|
|
|
|
|
/// A reason for inviting, declining, etc. a request.
|
2018-12-18 15:32:05 +01:00
|
|
|
|
Reason,
|
|
|
|
|
|
"reason",
|
|
|
|
|
|
MUC_USER
|
2018-08-08 20:22:37 +02:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// The affiliation of an entity with a room, which isn’t tied to its
|
|
|
|
|
|
/// presence in it.
|
|
|
|
|
|
Affiliation, "affiliation", {
|
|
|
|
|
|
/// The user who created the room, or who got appointed by its creator
|
|
|
|
|
|
/// to be their equal.
|
|
|
|
|
|
Owner => "owner",
|
|
|
|
|
|
|
|
|
|
|
|
/// A user who has been empowered by an owner to do administrative
|
|
|
|
|
|
/// operations.
|
|
|
|
|
|
Admin => "admin",
|
|
|
|
|
|
|
|
|
|
|
|
/// A user who is whitelisted to speak in moderated rooms, or to join a
|
|
|
|
|
|
/// member-only room.
|
|
|
|
|
|
Member => "member",
|
|
|
|
|
|
|
|
|
|
|
|
/// A user who has been banned from this room.
|
|
|
|
|
|
Outcast => "outcast",
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// A normal participant.
|
|
|
|
|
|
None => "none",
|
|
|
|
|
|
}, Default = None
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// The current role of an entity in a room, it can be changed by an owner
|
|
|
|
|
|
/// or an administrator but will be lost once they leave the room.
|
|
|
|
|
|
Role, "role", {
|
|
|
|
|
|
/// This user can kick other participants, as well as grant and revoke
|
|
|
|
|
|
/// them voice.
|
|
|
|
|
|
Moderator => "moderator",
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// A user who can speak in this room.
|
|
|
|
|
|
Participant => "participant",
|
2017-06-27 00:14:40 +01:00
|
|
|
|
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// A user who cannot speak in this room, and must request voice before
|
|
|
|
|
|
/// doing so.
|
|
|
|
|
|
Visitor => "visitor",
|
|
|
|
|
|
|
|
|
|
|
|
/// A user who is absent from the room.
|
|
|
|
|
|
None => "none",
|
|
|
|
|
|
}, Default = None
|
|
|
|
|
|
);
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2018-05-28 16:45:13 +02:00
|
|
|
|
generate_element!(
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// An item representing a user in a room.
|
2018-05-28 16:29:51 +02:00
|
|
|
|
Item, "item", MUC_USER, attributes: [
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// The affiliation of this user with the room.
|
2019-02-24 20:26:40 +01:00
|
|
|
|
affiliation: Required<Affiliation> = "affiliation",
|
2018-08-08 20:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
/// The real JID of this user, if you are allowed to see it.
|
2019-06-10 23:17:09 +02:00
|
|
|
|
jid: Option<FullJid> = "jid",
|
2018-08-08 20:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
/// The current nickname of this user.
|
2019-02-24 20:26:40 +01:00
|
|
|
|
nick: Option<String> = "nick",
|
2018-08-08 20:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
/// The current role of this user.
|
2019-02-24 20:26:40 +01:00
|
|
|
|
role: Required<Role> = "role",
|
2018-05-28 16:29:51 +02:00
|
|
|
|
], children: [
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// The actor affected by this item.
|
2018-05-28 16:29:51 +02:00
|
|
|
|
actor: Option<Actor> = ("actor", MUC_USER) => Actor,
|
2018-08-08 20:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
/// Whether this continues a one-to-one discussion.
|
2018-05-28 16:29:51 +02:00
|
|
|
|
continue_: Option<Continue> = ("continue", MUC_USER) => Continue,
|
2018-08-08 20:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
/// A reason for this item.
|
2018-05-28 16:29:51 +02:00
|
|
|
|
reason: Option<Reason> = ("reason", MUC_USER) => Reason
|
|
|
|
|
|
]
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-07-31 21:32:39 +02:00
|
|
|
|
impl Item {
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// Creates a new item with the given affiliation and role.
|
2018-07-31 21:32:39 +02:00
|
|
|
|
pub fn new(affiliation: Affiliation, role: Role) -> Item {
|
|
|
|
|
|
Item {
|
|
|
|
|
|
affiliation,
|
|
|
|
|
|
role,
|
|
|
|
|
|
jid: None,
|
|
|
|
|
|
nick: None,
|
|
|
|
|
|
actor: None,
|
|
|
|
|
|
continue_: None,
|
|
|
|
|
|
reason: None,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-12-27 12:52:24 +01:00
|
|
|
|
|
|
|
|
|
|
/// Set a jid for this Item
|
2022-12-27 16:31:58 +01:00
|
|
|
|
pub fn with_jid(mut self, jid: FullJid) -> Item {
|
|
|
|
|
|
self.jid = Some(jid);
|
2022-12-27 12:52:24 +01:00
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set a nick for this Item
|
|
|
|
|
|
pub fn with_nick<S: Into<String>>(mut self, nick: S) -> Item {
|
|
|
|
|
|
self.nick = Some(nick.into());
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set an actor for this Item
|
|
|
|
|
|
pub fn with_actor(mut self, actor: Actor) -> Item {
|
|
|
|
|
|
self.actor = Some(actor);
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set a continue value for this Item
|
|
|
|
|
|
pub fn with_continue<S: Into<String>>(mut self, continue_: S) -> Item {
|
|
|
|
|
|
self.continue_ = Some(Continue {
|
|
|
|
|
|
thread: Some(continue_.into()),
|
|
|
|
|
|
});
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set a reason for this Item
|
|
|
|
|
|
pub fn with_reason<S: Into<String>>(mut self, reason: S) -> Item {
|
|
|
|
|
|
self.reason = Some(Reason(reason.into()));
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
2018-07-31 21:32:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-28 16:45:13 +02:00
|
|
|
|
generate_element!(
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// The main muc#user element.
|
2018-05-28 16:29:51 +02:00
|
|
|
|
MucUser, "x", MUC_USER, children: [
|
2018-08-08 20:22:37 +02:00
|
|
|
|
/// List of statuses applying to this item.
|
2018-05-28 16:29:51 +02:00
|
|
|
|
status: Vec<Status> = ("status", MUC_USER) => Status,
|
2018-08-08 20:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
/// List of items.
|
2018-05-28 16:29:51 +02:00
|
|
|
|
items: Vec<Item> = ("item", MUC_USER) => Item
|
|
|
|
|
|
]
|
|
|
|
|
|
);
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
2023-06-07 18:40:08 +02:00
|
|
|
|
impl MucUser {
|
2023-06-07 19:17:06 +02:00
|
|
|
|
/// Creates an empty MucUser
|
2023-06-07 18:40:08 +02:00
|
|
|
|
pub fn new() -> MucUser {
|
|
|
|
|
|
MucUser {
|
|
|
|
|
|
status: vec![],
|
|
|
|
|
|
items: vec![],
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-07 19:17:06 +02:00
|
|
|
|
/// Set statuses for this MucUser
|
2023-06-07 19:16:55 +02:00
|
|
|
|
pub fn with_statuses(mut self, status: Vec<Status>) -> MucUser {
|
2023-06-07 18:40:08 +02:00
|
|
|
|
self.status = status;
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-07 19:17:06 +02:00
|
|
|
|
/// Set items for this MucUser
|
2023-06-07 18:40:08 +02:00
|
|
|
|
pub fn with_items(mut self, items: Vec<Item>) -> MucUser {
|
|
|
|
|
|
self.items = items;
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-07 16:46:43 +02:00
|
|
|
|
impl MessagePayload for MucUser {}
|
2022-09-10 11:34:45 +02:00
|
|
|
|
impl PresencePayload for MucUser {}
|
|
|
|
|
|
|
2017-06-26 23:07:12 +01:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
|
|
|
|
|
use super::*;
|
2023-06-07 16:46:43 +02:00
|
|
|
|
use crate::message::Message;
|
2022-09-10 11:34:45 +02:00
|
|
|
|
use crate::presence::{Presence, Type as PresenceType};
|
2023-06-20 14:07:50 +02:00
|
|
|
|
use crate::Jid;
|
2017-06-26 23:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_simple() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
MucUser::try_from(elem).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-28 16:29:51 +02:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn statuses_and_items() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'>
|
2018-05-28 16:29:51 +02:00
|
|
|
|
<status code='101'/>
|
|
|
|
|
|
<status code='102'/>
|
|
|
|
|
|
<item affiliation='member' role='moderator'/>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</x>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2018-05-28 16:29:51 +02:00
|
|
|
|
let muc_user = MucUser::try_from(elem).unwrap();
|
|
|
|
|
|
assert_eq!(muc_user.status.len(), 2);
|
|
|
|
|
|
assert_eq!(muc_user.status[0], Status::AffiliationChange);
|
|
|
|
|
|
assert_eq!(muc_user.status[1], Status::ConfigShowsUnavailableMembers);
|
|
|
|
|
|
assert_eq!(muc_user.items.len(), 1);
|
|
|
|
|
|
assert_eq!(muc_user.items[0].affiliation, Affiliation::Member);
|
|
|
|
|
|
assert_eq!(muc_user.items[0].role, Role::Moderator);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-26 23:07:12 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_invalid_child() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'>
|
2017-06-26 23:07:12 +01:00
|
|
|
|
<coucou/>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</x>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = MucUser::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Unknown child in x element.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_serialise() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2018-12-18 15:32:05 +01:00
|
|
|
|
let muc = MucUser {
|
|
|
|
|
|
status: vec![],
|
|
|
|
|
|
items: vec![],
|
|
|
|
|
|
};
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let elem2 = muc.into();
|
2019-11-29 14:33:17 +01:00
|
|
|
|
assert_eq!(elem, elem2);
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-12 22:00:46 +01:00
|
|
|
|
#[cfg(not(feature = "disable-validation"))]
|
2017-06-26 23:07:12 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_invalid_attribute() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user' coucou=''/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = MucUser::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Unknown attribute in x element.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_status_simple() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='110'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
Status::try_from(elem).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_status_invalid() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Status::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Required attribute 'code' missing.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-12 22:00:46 +01:00
|
|
|
|
#[cfg(not(feature = "disable-validation"))]
|
2017-06-26 23:07:12 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_status_invalid_child() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='110'>
|
2017-06-26 23:07:12 +01:00
|
|
|
|
<foo/>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</status>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Status::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Unknown child in status element.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_status_simple_code() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='307'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let status = Status::try_from(elem).unwrap();
|
|
|
|
|
|
assert_eq!(status, Status::Kicked);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_status_invalid_code() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='666'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Status::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2017-11-24 05:44:58 +00:00
|
|
|
|
assert_eq!(message, "Invalid status code value.");
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_status_invalid_code2() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='coucou'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Status::try_from(elem).unwrap_err();
|
|
|
|
|
|
let error = match error {
|
|
|
|
|
|
Error::ParseIntError(error) => error,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2020-01-21 23:46:00 +01:00
|
|
|
|
assert_eq!(error.to_string(), "invalid digit found in string");
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_actor_required_attributes() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Actor::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Either 'jid' or 'nick' attribute is required.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_actor_required_attributes2() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'
|
2017-06-26 23:07:12 +01:00
|
|
|
|
jid='foo@bar/baz'
|
2022-03-22 23:29:25 +01:00
|
|
|
|
nick='baz'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Actor::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Either 'jid' or 'nick' attribute is required.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_actor_jid() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'
|
|
|
|
|
|
jid='foo@bar/baz'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let actor = Actor::try_from(elem).unwrap();
|
|
|
|
|
|
let jid = match actor {
|
|
|
|
|
|
Actor::Jid(jid) => jid,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2019-06-10 23:17:09 +02:00
|
|
|
|
assert_eq!(jid, "foo@bar/baz".parse::<FullJid>().unwrap());
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_actor_nick() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user' nick='baz'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let actor = Actor::try_from(elem).unwrap();
|
|
|
|
|
|
let nick = match actor {
|
|
|
|
|
|
Actor::Nick(nick) => nick,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(nick, "baz".to_owned());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_continue_simple() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
Continue::try_from(elem).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_continue_thread_attribute() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'
|
|
|
|
|
|
thread='foo'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let continue_ = Continue::try_from(elem).unwrap();
|
2017-10-31 17:58:11 +00:00
|
|
|
|
assert_eq!(continue_.thread, Some("foo".to_owned()));
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_continue_invalid() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'>
|
2017-06-26 23:07:12 +01:00
|
|
|
|
<foobar/>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</continue>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let continue_ = Continue::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match continue_ {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Unknown child in continue element.".to_owned());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_reason_simple() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user'>Reason</reason>"
|
2018-12-18 15:32:05 +01:00
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2019-09-05 15:34:21 +02:00
|
|
|
|
let elem2 = elem.clone();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let reason = Reason::try_from(elem).unwrap();
|
|
|
|
|
|
assert_eq!(reason.0, "Reason".to_owned());
|
2019-09-05 15:34:21 +02:00
|
|
|
|
|
|
|
|
|
|
let elem3 = reason.into();
|
|
|
|
|
|
assert_eq!(elem2, elem3);
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-12 22:00:46 +01:00
|
|
|
|
#[cfg(not(feature = "disable-validation"))]
|
2017-06-26 23:07:12 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_reason_invalid_attribute() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user' foo='bar'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Reason::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Unknown attribute in reason element.".to_owned());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-12 22:00:46 +01:00
|
|
|
|
#[cfg(not(feature = "disable-validation"))]
|
2017-06-26 23:07:12 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_reason_invalid() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user'>
|
2017-06-26 23:07:12 +01:00
|
|
|
|
<foobar/>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</reason>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Reason::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Unknown child in reason element.".to_owned());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-12 22:00:46 +01:00
|
|
|
|
#[cfg(not(feature = "disable-validation"))]
|
2017-06-26 23:07:12 +01:00
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_invalid_attr() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
|
|
|
|
|
foo='bar'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Item::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Unknown attribute in item element.".to_owned());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_affiliation_role_attr() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
2017-06-26 23:07:12 +01:00
|
|
|
|
affiliation='member'
|
2022-03-22 23:29:25 +01:00
|
|
|
|
role='moderator'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
Item::try_from(elem).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_affiliation_role_invalid_attr() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
|
|
|
|
|
affiliation='member'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Item::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(message, "Required attribute 'role' missing.".to_owned());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_nick_attr() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
2017-06-26 23:07:12 +01:00
|
|
|
|
affiliation='member'
|
|
|
|
|
|
role='moderator'
|
2022-03-22 23:29:25 +01:00
|
|
|
|
nick='foobar'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let item = Item::try_from(elem).unwrap();
|
|
|
|
|
|
match item {
|
|
|
|
|
|
Item { nick, .. } => assert_eq!(nick, Some("foobar".to_owned())),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_affiliation_role_invalid_attr2() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
|
|
|
|
|
role='moderator'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let error = Item::try_from(elem).unwrap_err();
|
|
|
|
|
|
let message = match error {
|
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2018-12-18 15:32:05 +01:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message,
|
|
|
|
|
|
"Required attribute 'affiliation' missing.".to_owned()
|
|
|
|
|
|
);
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_role_actor_child() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
2017-06-26 23:07:12 +01:00
|
|
|
|
affiliation='member'
|
|
|
|
|
|
role='moderator'>
|
|
|
|
|
|
<actor nick='foobar'/>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</item>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let item = Item::try_from(elem).unwrap();
|
|
|
|
|
|
match item {
|
2018-12-18 15:32:05 +01:00
|
|
|
|
Item { actor, .. } => assert_eq!(actor, Some(Actor::Nick("foobar".to_owned()))),
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_role_continue_child() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
2017-06-26 23:07:12 +01:00
|
|
|
|
affiliation='member'
|
|
|
|
|
|
role='moderator'>
|
|
|
|
|
|
<continue thread='foobar'/>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</item>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let item = Item::try_from(elem).unwrap();
|
2018-12-18 15:32:05 +01:00
|
|
|
|
let continue_1 = Continue {
|
|
|
|
|
|
thread: Some("foobar".to_owned()),
|
|
|
|
|
|
};
|
2017-06-26 23:07:12 +01:00
|
|
|
|
match item {
|
2018-12-18 15:32:05 +01:00
|
|
|
|
Item {
|
|
|
|
|
|
continue_: Some(continue_2),
|
|
|
|
|
|
..
|
|
|
|
|
|
} => assert_eq!(continue_2.thread, continue_1.thread),
|
2017-06-26 23:07:12 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2018-12-18 15:32:05 +01:00
|
|
|
|
fn test_item_role_reason_child() {
|
2022-03-22 23:29:25 +01:00
|
|
|
|
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
2017-06-26 23:07:12 +01:00
|
|
|
|
affiliation='member'
|
|
|
|
|
|
role='moderator'>
|
|
|
|
|
|
<reason>foobar</reason>
|
2022-03-22 23:29:25 +01:00
|
|
|
|
</item>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-06-26 23:07:12 +01:00
|
|
|
|
let item = Item::try_from(elem).unwrap();
|
|
|
|
|
|
match item {
|
2018-12-18 15:32:05 +01:00
|
|
|
|
Item { reason, .. } => assert_eq!(reason, Some(Reason("foobar".to_owned()))),
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-28 18:00:40 +01:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_serialize_item() {
|
2019-12-05 21:57:20 +01:00
|
|
|
|
let reference: Element = "<item xmlns='http://jabber.org/protocol/muc#user' affiliation='member' role='moderator'><actor nick='foobar'/><continue thread='foobar'/><reason>foobar</reason></item>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user' nick='foobar'/>"
|
2019-12-30 07:35:32 +01:40
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2019-12-05 21:57:20 +01:00
|
|
|
|
let actor = Actor::try_from(elem).unwrap();
|
|
|
|
|
|
|
2019-12-30 07:35:32 +01:40
|
|
|
|
let elem: Element =
|
|
|
|
|
|
"<continue xmlns='http://jabber.org/protocol/muc#user' thread='foobar'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2019-12-05 21:57:20 +01:00
|
|
|
|
let continue_ = Continue::try_from(elem).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user'>foobar</reason>"
|
2019-12-30 07:35:32 +01:40
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2019-12-05 21:57:20 +01:00
|
|
|
|
let reason = Reason::try_from(elem).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let item = Item {
|
|
|
|
|
|
affiliation: Affiliation::Member,
|
|
|
|
|
|
role: Role::Moderator,
|
|
|
|
|
|
jid: None,
|
|
|
|
|
|
nick: None,
|
|
|
|
|
|
actor: Some(actor),
|
|
|
|
|
|
reason: Some(reason),
|
|
|
|
|
|
continue_: Some(continue_),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let serialized: Element = item.into();
|
|
|
|
|
|
assert_eq!(serialized, reference);
|
2019-11-28 18:00:40 +01:00
|
|
|
|
}
|
2022-09-10 11:34:45 +02:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn presence_payload() {
|
|
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2022-09-16 19:57:20 +02:00
|
|
|
|
let presence = Presence::new(PresenceType::None).with_payloads(vec![elem]);
|
2022-09-10 11:34:45 +02:00
|
|
|
|
assert_eq!(presence.payloads.len(), 1);
|
|
|
|
|
|
}
|
2023-06-07 16:46:43 +02:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn message_payload() {
|
2023-06-20 14:07:50 +02:00
|
|
|
|
let jid: Jid = Jid::new("louise@example.com").unwrap();
|
2023-06-07 16:46:43 +02:00
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
let message = Message::new(jid).with_payloads(vec![elem]);
|
|
|
|
|
|
assert_eq!(message.payloads.len(), 1);
|
|
|
|
|
|
}
|
2017-06-26 23:07:12 +01:00
|
|
|
|
}
|