xmpp: Agent::send_room_private_message takes RoomPrivateMessageSettings
This commit is contained in:
parent
897c2abe0b
commit
d98ed615a5
3 changed files with 45 additions and 20 deletions
|
|
@ -11,6 +11,7 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
|
||||||
- Event::RoomMessage, Event::RoomPrivateMessage, and Event::RoomSubject now
|
- Event::RoomMessage, Event::RoomPrivateMessage, and Event::RoomSubject now
|
||||||
use RoomNick as sender nickname; previously RoomNick was an alias for String
|
use RoomNick as sender nickname; previously RoomNick was an alias for String
|
||||||
now it's a newtype wrapper around ResourcePart (!485)
|
now it's a newtype wrapper around ResourcePart (!485)
|
||||||
|
- Agent::send_room_private_message now takes RoomPrivateMessageSettings (!487)
|
||||||
* Added:
|
* Added:
|
||||||
- Agent::send_room_message takes RoomMessageSettings argument (!483)
|
- Agent::send_room_message takes RoomMessageSettings argument (!483)
|
||||||
* Fixes:
|
* Fixes:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub use tokio_xmpp::{
|
||||||
Client as TokioXmppClient,
|
Client as TokioXmppClient,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{event_loop, message, muc, upload, Error, Event, RoomNick};
|
use crate::{event_loop, message, muc, upload, Error, Event};
|
||||||
|
|
||||||
pub struct Agent {
|
pub struct Agent {
|
||||||
pub(crate) client: TokioXmppClient,
|
pub(crate) client: TokioXmppClient,
|
||||||
|
|
@ -63,14 +63,11 @@ impl Agent {
|
||||||
muc::room::send_room_message(self, settings).await
|
muc::room::send_room_message(self, settings).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_room_private_message(
|
pub async fn send_room_private_message<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
room: BareJid,
|
settings: muc::private_message::RoomPrivateMessageSettings<'a>,
|
||||||
recipient: RoomNick,
|
|
||||||
lang: &str,
|
|
||||||
text: &str,
|
|
||||||
) {
|
) {
|
||||||
muc::private_message::send_room_private_message(self, room, recipient, lang, text).await
|
muc::private_message::send_room_private_message(self, settings).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for new events, or Error::Disconnected when connection is closed and will not reconnect.
|
/// Wait for new events, or Error::Disconnected when connection is closed and will not reconnect.
|
||||||
|
|
|
||||||
|
|
@ -4,28 +4,55 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use tokio_xmpp::{
|
use crate::{
|
||||||
jid::{BareJid, Jid},
|
|
||||||
parsers::{
|
parsers::{
|
||||||
message::{Body, Message, MessageType},
|
message::{Body, Message, MessageType},
|
||||||
muc::user::MucUser,
|
muc::user::MucUser,
|
||||||
},
|
},
|
||||||
|
tokio_xmpp::jid::{BareJid, Jid},
|
||||||
|
Agent, RoomNick,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{Agent, RoomNick};
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct RoomPrivateMessageSettings<'a> {
|
||||||
pub async fn send_room_private_message(
|
pub room: BareJid,
|
||||||
agent: &mut Agent,
|
pub recipient: RoomNick,
|
||||||
room: BareJid,
|
pub message: &'a str,
|
||||||
recipient: RoomNick,
|
pub lang: Option<&'a str>,
|
||||||
lang: &str,
|
}
|
||||||
text: &str,
|
|
||||||
) {
|
impl<'a> RoomPrivateMessageSettings<'a> {
|
||||||
let recipient: Jid = room.with_resource(recipient.as_ref()).into();
|
pub fn new(room: BareJid, recipient: RoomNick, message: &'a str) -> Self {
|
||||||
let mut message = Message::new(recipient).with_payload(MucUser::new());
|
Self {
|
||||||
message.type_ = MessageType::Chat;
|
room,
|
||||||
message
|
recipient,
|
||||||
.bodies
|
message,
|
||||||
.insert(String::from(lang), Body(String::from(text)));
|
lang: None,
|
||||||
let _ = agent.client.send_stanza(message.into()).await;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_lang(mut self, lang: &'a str) -> Self {
|
||||||
|
self.lang = Some(lang);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn send_room_private_message<'a>(
|
||||||
|
agent: &mut Agent,
|
||||||
|
settings: RoomPrivateMessageSettings<'a>,
|
||||||
|
) {
|
||||||
|
let RoomPrivateMessageSettings {
|
||||||
|
room,
|
||||||
|
recipient,
|
||||||
|
message,
|
||||||
|
lang,
|
||||||
|
} = settings;
|
||||||
|
|
||||||
|
let recipient: Jid = room.with_resource(recipient.as_ref()).into();
|
||||||
|
let mut stanza = Message::new(recipient).with_payload(MucUser::new());
|
||||||
|
stanza.type_ = MessageType::Chat;
|
||||||
|
stanza
|
||||||
|
.bodies
|
||||||
|
.insert(lang.unwrap_or("").to_string(), Body(String::from(message)));
|
||||||
|
agent.client.send_stanza(stanza.into()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue