1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
//! This module contains convenience methods related to creating bookmarks.
use crate::parsers::pubsub::access_model::AccessModel;
use crate::{
iq::bookmark::bookmarks2::Autojoin, iq::bookmark::pubsub::pubsub::PublishOptions,
iq::bookmark::pubsub::send_last_published::SendLastPublished, iq::bookmark::pubsub::ItemId,
iq::bookmark::pubsub::NodeName, iq::bookmark::pubsub::PubSub::Publish, iq::Iq,
parsers::bookmarks2, parsers::ns::BOOKMARKS2, parsers::pubsub, BareJid,
};
/// Create the `<iq>` stanza that will create a new (MUC) room bookmark.
///
/// # Arguments
/// * room: The Jid of the room itself.
/// * auto_join: Whether to auto-join on client startup
/// * user_nick: The name of the user within the room.
/// * room_name: A user-friendly name for the room.
/// * password: The password of the room, if applicable.
pub fn create_muc_bookmark_iq(
room: &BareJid,
auto_join: bool,
user_nick: Option<String>,
room_name: Option<String>,
password: Option<String>,
) -> Iq {
// Create an Iq stanza that specifies that we wish to set a bookmark.
let bookmark = bookmarks2::Conference {
autojoin: if auto_join {
Autojoin::True
} else {
Autojoin::False
},
name: room_name,
nick: user_nick,
password,
extensions: vec![],
};
let item = pubsub::Item {
id: Some(ItemId(room.to_string())),
publisher: None,
payload: Some(bookmark.into()),
};
let iq = Iq::from_set(
"create-bookmark",
// We'd like to publish a new item.
Publish {
// What we would like to publish.
publish: crate::parsers::pubsub::pubsub::Publish {
// Put us into the 0402 bookmarks namespace
node: NodeName(BOOKMARKS2.to_string()),
items: vec![pubsub::pubsub::Item(item)],
},
publish_options: Some(PublishOptions::new(
true,
None,
SendLastPublished::Never,
AccessModel::Whitelist,
)),
},
);
iq
}