xmpp: Rewrite other messages with Agent::send_raw_message
This commit is contained in:
parent
b4d3252da4
commit
0ec9103b28
3 changed files with 28 additions and 26 deletions
|
|
@ -37,6 +37,11 @@ impl<'a> RawMessageSettings<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_lang_option(mut self, lang: Option<&'a str>) -> Self {
|
||||
self.lang = lang;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_payload(mut self, payload: impl MessagePayload) -> Self {
|
||||
self.payloads.push(payload.into());
|
||||
self
|
||||
|
|
@ -94,12 +99,11 @@ pub async fn send_message<'a>(agent: &mut Agent, settings: MessageSettings<'a>)
|
|||
lang,
|
||||
} = settings;
|
||||
|
||||
// TODO: check that recipient may receive normal chat message, eg is not a MUC chatroom
|
||||
|
||||
let mut stanza = Message::new(Some(recipient.into()));
|
||||
stanza.type_ = MessageType::Chat;
|
||||
stanza
|
||||
.bodies
|
||||
.insert(lang.unwrap_or("").to_string(), Body(String::from(message)));
|
||||
agent.client.send_stanza(stanza.into()).await.unwrap();
|
||||
// TODO: check that recipient is not in agent.joined_rooms
|
||||
agent
|
||||
.send_raw_message(
|
||||
RawMessageSettings::new(recipient.into(), MessageType::Chat, message)
|
||||
.with_lang_option(lang),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@
|
|||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
use crate::{
|
||||
parsers::{
|
||||
message::{Body, Message, MessageType},
|
||||
muc::user::MucUser,
|
||||
},
|
||||
message::send::RawMessageSettings,
|
||||
parsers::{message::MessageType, muc::user::MucUser},
|
||||
tokio_xmpp::jid::{BareJid, Jid},
|
||||
Agent, RoomNick,
|
||||
};
|
||||
|
|
@ -50,10 +48,11 @@ pub async fn send_room_private_message<'a>(
|
|||
|
||||
// TODO: check that room is in agent.joined_rooms
|
||||
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();
|
||||
agent
|
||||
.send_raw_message(
|
||||
RawMessageSettings::new(recipient, MessageType::Chat, message)
|
||||
.with_payload(MucUser::new())
|
||||
.with_lang_option(lang),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ use crate::parsers::message::MessageType;
|
|||
use tokio_xmpp::{
|
||||
jid::{BareJid, ResourcePart, ResourceRef},
|
||||
parsers::{
|
||||
message::{Body, Message},
|
||||
muc::Muc,
|
||||
presence::{Presence, Type as PresenceType},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::message::send::RawMessageSettings;
|
||||
use crate::Agent;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -190,11 +190,10 @@ pub async fn send_room_message<'a>(agent: &mut Agent, settings: RoomMessageSetti
|
|||
} = settings;
|
||||
|
||||
// TODO: check that room is in agent.joined_rooms
|
||||
|
||||
let mut stanza = Message::new(Some(room.into()));
|
||||
stanza.type_ = MessageType::Groupchat;
|
||||
stanza
|
||||
.bodies
|
||||
.insert(lang.unwrap_or("").to_string(), Body(String::from(message)));
|
||||
agent.client.send_stanza(stanza.into()).await.unwrap();
|
||||
agent
|
||||
.send_raw_message(
|
||||
RawMessageSettings::new(room.into(), MessageType::Groupchat, message)
|
||||
.with_lang_option(lang),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue