2017-06-11 14:48:31 +01:00
|
|
|
|
// Copyright (c) 2017 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/.
|
|
|
|
|
|
|
2018-05-15 00:18:15 +02:00
|
|
|
|
/// The `http://jabber.org/protocol/pubsub#event` protocol.
|
2017-06-11 14:48:31 +01:00
|
|
|
|
pub mod event;
|
2018-05-15 00:18:15 +02:00
|
|
|
|
|
2020-09-27 11:33:11 +02:00
|
|
|
|
/// The `http://jabber.org/protocol/pubsub#owner` protocol.
|
|
|
|
|
|
pub mod owner;
|
|
|
|
|
|
|
2018-05-15 00:18:15 +02:00
|
|
|
|
/// The `http://jabber.org/protocol/pubsub` protocol.
|
2018-05-14 21:04:16 +02:00
|
|
|
|
pub mod pubsub;
|
2017-06-11 14:48:31 +01:00
|
|
|
|
|
|
|
|
|
|
pub use self::event::PubSubEvent;
|
2020-09-27 11:33:11 +02:00
|
|
|
|
pub use self::owner::PubSubOwner;
|
2018-05-14 21:04:16 +02:00
|
|
|
|
pub use self::pubsub::PubSub;
|
2018-05-14 17:49:25 +02:00
|
|
|
|
|
2019-10-23 01:32:41 +02:00
|
|
|
|
use crate::{Element, Jid};
|
2019-01-27 18:57:25 +01:00
|
|
|
|
|
2018-08-02 22:16:55 +02:00
|
|
|
|
generate_id!(
|
|
|
|
|
|
/// The name of a PubSub node, used to identify it on a JID.
|
|
|
|
|
|
NodeName
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_id!(
|
|
|
|
|
|
/// The identifier of an item, which is unique per node.
|
|
|
|
|
|
ItemId
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_id!(
|
|
|
|
|
|
/// The identifier of a subscription to a PubSub node.
|
|
|
|
|
|
SubscriptionId
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// The state of a subscription to a node.
|
|
|
|
|
|
Subscription, "subscription", {
|
|
|
|
|
|
/// The user is not subscribed to this node.
|
|
|
|
|
|
None => "none",
|
|
|
|
|
|
|
|
|
|
|
|
/// The user’s subscription to this node is still pending.
|
|
|
|
|
|
Pending => "pending",
|
|
|
|
|
|
|
|
|
|
|
|
/// The user is subscribed to this node.
|
|
|
|
|
|
Subscribed => "subscribed",
|
2018-05-14 21:02:22 +02:00
|
|
|
|
|
2018-08-02 22:16:55 +02:00
|
|
|
|
/// The user’s subscription to this node will only be valid once
|
|
|
|
|
|
/// configured.
|
|
|
|
|
|
Unconfigured => "unconfigured",
|
|
|
|
|
|
}, Default = None
|
|
|
|
|
|
);
|
2019-01-27 17:40:46 +01:00
|
|
|
|
|
2020-09-28 22:33:08 +02:00
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// A list of possible affiliations to a node.
|
|
|
|
|
|
AffiliationAttribute, "affiliation", {
|
|
|
|
|
|
/// You are a member of this node, you can subscribe and retrieve items.
|
|
|
|
|
|
Member => "member",
|
|
|
|
|
|
|
|
|
|
|
|
/// You don’t have a specific affiliation with this node, you can only subscribe to it.
|
|
|
|
|
|
None => "none",
|
|
|
|
|
|
|
|
|
|
|
|
/// You are banned from this node.
|
|
|
|
|
|
Outcast => "outcast",
|
|
|
|
|
|
|
|
|
|
|
|
/// You are an owner of this node, and can do anything with it.
|
|
|
|
|
|
Owner => "owner",
|
|
|
|
|
|
|
|
|
|
|
|
/// You are a publisher on this node, you can publish and retract items to it.
|
|
|
|
|
|
Publisher => "publisher",
|
|
|
|
|
|
|
|
|
|
|
|
/// You can publish and retract items on this node, but not subscribe or retrieve items.
|
|
|
|
|
|
PublishOnly => "publish-only",
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2019-01-27 18:57:25 +01:00
|
|
|
|
/// An item from a PubSub node.
|
2020-11-29 21:17:51 +01:00
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2019-01-27 18:57:25 +01:00
|
|
|
|
pub struct Item {
|
|
|
|
|
|
/// The identifier for this item, unique per node.
|
|
|
|
|
|
pub id: Option<ItemId>,
|
|
|
|
|
|
|
|
|
|
|
|
/// The JID of the entity who published this item.
|
|
|
|
|
|
pub publisher: Option<Jid>,
|
|
|
|
|
|
|
|
|
|
|
|
/// The payload of this item, in an arbitrary namespace.
|
|
|
|
|
|
pub payload: Option<Element>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Item {
|
|
|
|
|
|
/// Create a new item, accepting only payloads implementing `PubSubPayload`.
|
2019-10-23 01:32:41 +02:00
|
|
|
|
pub fn new<P: PubSubPayload>(
|
|
|
|
|
|
id: Option<ItemId>,
|
|
|
|
|
|
publisher: Option<Jid>,
|
|
|
|
|
|
payload: Option<P>,
|
|
|
|
|
|
) -> Item {
|
2019-01-27 18:57:25 +01:00
|
|
|
|
Item {
|
|
|
|
|
|
id,
|
|
|
|
|
|
publisher,
|
2019-02-21 21:00:58 +01:00
|
|
|
|
payload: payload.map(Into::into),
|
2019-01-27 18:57:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-27 17:40:46 +01:00
|
|
|
|
/// This trait should be implemented on any element which can be included as a PubSub payload.
|
2019-07-17 22:30:49 +02:00
|
|
|
|
pub trait PubSubPayload: ::std::convert::TryFrom<crate::Element> + Into<crate::Element> {}
|