From 9c39e3c195ea087b5ed25285ee33f700c3acff0d Mon Sep 17 00:00:00 2001 From: xmppftw Date: Wed, 7 Jun 2023 16:38:03 +0200 Subject: [PATCH] Event::RoomPrivateMessage does not expose sender FullJid ; add Agent::send_room_private_message method --- xmpp/src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index f23b1100..41d55ade 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -91,8 +91,8 @@ pub enum Event { RoomLeft(BareJid), RoomMessage(Id, BareJid, RoomNick, Body), /// A private message received from a room, containing the message ID, the room's BareJid, - /// the sender's FullJid, the corresponding nickname, and the message body. - RoomPrivateMessage(Id, BareJid, FullJid, RoomNick, Body), + /// the sender's nickname, and the message body. + RoomPrivateMessage(Id, BareJid, RoomNick, Body), ServiceMessage(Id, BareJid, Body), HttpUploadedFile(String), } @@ -255,6 +255,18 @@ impl Agent { let _ = self.client.send_stanza(message.into()).await; } + pub async fn send_room_private_message( + &mut self, + room: BareJid, + recipient: RoomNick, + type_: MessageType, + lang: &str, + text: &str, + ) { + let recipient = room.with_resource(recipient); + self.send_message(recipient.into(), type_, lang, text).await + } + fn make_initial_presence(disco: &DiscoInfoResult, node: &str) -> Presence { let caps_data = compute_disco(disco); let hash = hash_caps(&caps_data, Algo::Sha_1).unwrap(); @@ -272,7 +284,7 @@ impl Agent { .clone() .unwrap_or_else(|| self.client.bound_jid().unwrap().clone()); if let IqType::Get(payload) = iq.payload { - if payload.is("query", ns::DISCO_INFO) { + if MucUser::try_from(payload.clone()).is_ok() { let query = DiscoInfoQuery::try_from(payload); match query { Ok(query) => { @@ -375,7 +387,6 @@ impl Agent { Jid::Full(full) => Event::RoomPrivateMessage( message.id.clone(), full.clone().into(), - full.clone(), full.resource, body.clone(), ),