From 0e317399348c43014dcc70ca867ebadfd411c4fa Mon Sep 17 00:00:00 2001 From: "xmppftw@kl.netlib.re" Date: Sat, 30 Dec 2023 00:33:04 +0100 Subject: [PATCH] Move send_room_private_message to muc::private_message module --- xmpp/src/lib.rs | 9 +-------- xmpp/src/muc/mod.rs | 1 + xmpp/src/muc/private_message.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 xmpp/src/muc/private_message.rs diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index a213288..16d9d3e 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -12,7 +12,6 @@ pub use tokio_xmpp::parsers; use tokio_xmpp::parsers::{ disco::DiscoInfoResult, message::{Body, Message, MessageType}, - muc::user::MucUser, }; use tokio_xmpp::AsyncClient as TokioXmppClient; pub use tokio_xmpp::{BareJid, Element, FullJid, Jid}; @@ -120,13 +119,7 @@ impl Agent { lang: &str, text: &str, ) { - let recipient: Jid = room.with_resource_str(&recipient).unwrap().into(); - let mut message = Message::new(recipient).with_payload(MucUser::new()); - message.type_ = MessageType::Chat; - message - .bodies - .insert(String::from(lang), Body(String::from(text))); - let _ = self.client.send_stanza(message.into()).await; + muc::private_message::send_room_private_message(self, room, recipient, lang, text).await } /// Wait for new events. diff --git a/xmpp/src/muc/mod.rs b/xmpp/src/muc/mod.rs index a3c4b46..ddd73b4 100644 --- a/xmpp/src/muc/mod.rs +++ b/xmpp/src/muc/mod.rs @@ -4,4 +4,5 @@ // 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/. +pub mod private_message; pub mod room; diff --git a/xmpp/src/muc/private_message.rs b/xmpp/src/muc/private_message.rs new file mode 100644 index 0000000..cdf9e26 --- /dev/null +++ b/xmpp/src/muc/private_message.rs @@ -0,0 +1,31 @@ +// Copyright (c) 2023 xmpp-rs contributors. +// +// 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/. + +use tokio_xmpp::{ + parsers::{ + message::{Body, Message, MessageType}, + muc::user::MucUser, + }, + BareJid, Jid, +}; + +use crate::{Agent, RoomNick}; + +pub async fn send_room_private_message( + agent: &mut Agent, + room: BareJid, + recipient: RoomNick, + lang: &str, + text: &str, +) { + let recipient: Jid = room.with_resource_str(&recipient).unwrap().into(); + let mut message = Message::new(recipient).with_payload(MucUser::new()); + message.type_ = MessageType::Chat; + message + .bodies + .insert(String::from(lang), Body(String::from(text))); + let _ = agent.client.send_stanza(message.into()).await; +}