xmpp/muc/
private_message.rs1use crate::{
8 jid::{BareJid, Jid},
9 message::send::RawMessageSettings,
10 parsers::{message::MessageType, muc::user::MucUser},
11 Agent, RoomNick,
12};
13
14#[derive(Clone, Debug)]
15pub struct RoomPrivateMessageSettings<'a> {
16 pub room: BareJid,
17 pub recipient: RoomNick,
18 pub message: &'a str,
19 pub lang: Option<&'a str>,
20}
21
22impl<'a> RoomPrivateMessageSettings<'a> {
23 pub fn new(room: BareJid, recipient: RoomNick, message: &'a str) -> Self {
24 Self {
25 room,
26 recipient,
27 message,
28 lang: None,
29 }
30 }
31
32 pub fn with_lang(mut self, lang: &'a str) -> Self {
33 self.lang = Some(lang);
34 self
35 }
36}
37
38pub async fn send_room_private_message<'a>(
39 agent: &mut Agent,
40 settings: RoomPrivateMessageSettings<'a>,
41) {
42 let RoomPrivateMessageSettings {
43 room,
44 recipient,
45 message,
46 lang,
47 } = settings;
48
49 let recipient: Jid = room.with_resource(recipient.as_ref()).into();
51 agent
52 .send_raw_message(
53 RawMessageSettings::new(recipient, MessageType::Chat, message)
54 .with_payload(MucUser::new())
55 .with_lang_option(lang),
56 )
57 .await;
58}