From f6c47dd394d4aca54bdff7752ae40ce28164e503 Mon Sep 17 00:00:00 2001 From: "xmppftw@kl.netlib.re" Date: Sat, 30 Dec 2023 00:38:06 +0100 Subject: [PATCH] Move send_message to message::send module --- xmpp/src/lib.rs | 12 ++---------- xmpp/src/message/mod.rs | 1 + xmpp/src/message/send.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 xmpp/src/message/send.rs diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index 16d9d3e..dc1bd46 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -9,10 +9,7 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; pub use tokio_xmpp::parsers; -use tokio_xmpp::parsers::{ - disco::DiscoInfoResult, - message::{Body, Message, MessageType}, -}; +use tokio_xmpp::parsers::{disco::DiscoInfoResult, message::MessageType}; use tokio_xmpp::AsyncClient as TokioXmppClient; pub use tokio_xmpp::{BareJid, Element, FullJid, Jid}; #[macro_use] @@ -104,12 +101,7 @@ impl Agent { lang: &str, text: &str, ) { - let mut message = Message::new(Some(recipient)); - message.type_ = type_; - message - .bodies - .insert(String::from(lang), Body(String::from(text))); - let _ = self.client.send_stanza(message.into()).await; + message::send::send_message(self, recipient, type_, lang, text).await } pub async fn send_room_private_message( diff --git a/xmpp/src/message/mod.rs b/xmpp/src/message/mod.rs index ce689d6..f38387b 100644 --- a/xmpp/src/message/mod.rs +++ b/xmpp/src/message/mod.rs @@ -5,3 +5,4 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. pub mod receive; +pub mod send; diff --git a/xmpp/src/message/send.rs b/xmpp/src/message/send.rs new file mode 100644 index 0000000..539c5a7 --- /dev/null +++ b/xmpp/src/message/send.rs @@ -0,0 +1,27 @@ +// 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}, + Jid, +}; + +use crate::Agent; + +pub async fn send_message( + agent: &mut Agent, + recipient: Jid, + type_: MessageType, + lang: &str, + text: &str, +) { + let mut message = Message::new(Some(recipient)); + message.type_ = type_; + message + .bodies + .insert(String::from(lang), Body(String::from(text))); + let _ = agent.client.send_stanza(message.into()).await; +}