mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-03 03:40:36 +02:00
Factored out create_muc_join_presence_stanza function.
This commit is contained in:
parent
2f7d5edb8a
commit
1868afeda3
|
@ -23,17 +23,48 @@ pub async fn join_room<C: ServerConnector>(
|
|||
lang: &str,
|
||||
status: &str,
|
||||
) {
|
||||
let nick = nick.unwrap_or_else(|| agent.default_nick.read().unwrap().clone());
|
||||
let presence = create_muc_join_presence_stanza(room, password, lang, status, &nick);
|
||||
let _ = agent.client.send_stanza(presence.into()).await;
|
||||
}
|
||||
|
||||
/// Create a Presence stanza for joining a MUC room with a specific nickname.
|
||||
///
|
||||
/// # Arguments
|
||||
/// - `room`: The JID of the room to join.
|
||||
/// - `password`: The password to use to join the room, if any.
|
||||
/// - `lang`: The language of the status message.
|
||||
/// - `status`: The status message to send.
|
||||
/// - `nick`: The nickname to use in the room.
|
||||
pub fn create_muc_join_presence_stanza(
|
||||
room: BareJid,
|
||||
password: Option<String>,
|
||||
lang: &str,
|
||||
status: &str,
|
||||
nick: &String,
|
||||
) -> Presence {
|
||||
// Combine the room JID with the nickname to create the JID of the room occupant.
|
||||
let room_jid = room.with_resource_str(&nick).unwrap();
|
||||
|
||||
// Create a presence stanza.
|
||||
let mut presence = Presence::new(PresenceType::None).with_to(room_jid);
|
||||
|
||||
// MUC presence stanza's must have a Muc payload.
|
||||
let mut muc = Muc::new();
|
||||
|
||||
// If a password is provided, include it in the Muc payload.
|
||||
if let Some(password) = password {
|
||||
muc = muc.with_password(password);
|
||||
}
|
||||
|
||||
let nick = nick.unwrap_or_else(|| agent.default_nick.read().unwrap().clone());
|
||||
let room_jid = room.with_resource_str(&nick).unwrap();
|
||||
let mut presence = Presence::new(PresenceType::None).with_to(room_jid);
|
||||
// Add the Muc payload to the presence stanza.
|
||||
presence.add_payload(muc);
|
||||
|
||||
// Set the user-readable status message.
|
||||
presence.set_status(String::from(lang), String::from(status));
|
||||
let _ = agent.client.send_stanza(presence.into()).await;
|
||||
|
||||
// Return the presence stanza.
|
||||
presence
|
||||
}
|
||||
|
||||
/// Send a "leave room" request to the server (specifically, an "unavailable" presence stanza).
|
||||
|
|
Loading…
Reference in New Issue
Block a user