private_message.rs

 1// Copyright (c) 2023 xmpp-rs contributors.
 2//
 3// This Source Code Form is subject to the terms of the Mozilla Public
 4// License, v. 2.0. If a copy of the MPL was not distributed with this
 5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
 6
 7use tokio_xmpp::connect::ServerConnector;
 8use tokio_xmpp::{
 9    parsers::{
10        message::{Body, Message, MessageType},
11        muc::user::MucUser,
12    },
13    BareJid, Jid,
14};
15
16use crate::{Agent, RoomNick};
17
18pub async fn send_room_private_message<C: ServerConnector>(
19    agent: &mut Agent<C>,
20    room: BareJid,
21    recipient: RoomNick,
22    lang: &str,
23    text: &str,
24) {
25    let recipient: Jid = room.with_resource_str(&recipient).unwrap().into();
26    let mut message = Message::new(recipient).with_payload(MucUser::new());
27    message.type_ = MessageType::Chat;
28    message
29        .bodies
30        .insert(String::from(lang), Body(String::from(text)));
31    let _ = agent.client.send_stanza(message.into()).await;
32}