2023-10-13 20:09:08 +00:00
|
|
|
//! Handling of all client2server message stanzas
|
|
|
|
|
|
|
|
use quick_xml::events::Event;
|
|
|
|
|
|
|
|
use lavina_core::prelude::*;
|
|
|
|
use lavina_core::room::RoomId;
|
|
|
|
use proto_xmpp::bind::{Jid, Server};
|
|
|
|
use proto_xmpp::client::{Message, MessageType};
|
|
|
|
use proto_xmpp::xml::{Ignore, ToXml};
|
|
|
|
|
|
|
|
use crate::XmppConnection;
|
|
|
|
|
|
|
|
impl<'a> XmppConnection<'a> {
|
|
|
|
pub async fn handle_message(&mut self, output: &mut Vec<Event<'static>>, m: Message<Ignore>) -> Result<()> {
|
|
|
|
if let Some(Jid {
|
|
|
|
name: Some(name),
|
|
|
|
server,
|
|
|
|
resource: _,
|
|
|
|
}) = m.to
|
|
|
|
{
|
|
|
|
if server.0.as_ref() == "rooms.localhost" && m.r#type == MessageType::Groupchat {
|
2023-10-13 14:54:08 +00:00
|
|
|
self.user_handle.send_message(RoomId::from(name.0.clone())?, m.body.clone().into()).await?;
|
2023-10-13 20:09:08 +00:00
|
|
|
Message::<()> {
|
|
|
|
to: Some(Jid {
|
|
|
|
name: Some(self.user.xmpp_name.clone()),
|
|
|
|
server: Server("localhost".into()),
|
|
|
|
resource: Some(self.user.xmpp_resource.clone()),
|
|
|
|
}),
|
|
|
|
from: Some(Jid {
|
|
|
|
name: Some(name),
|
|
|
|
server: Server("rooms.localhost".into()),
|
|
|
|
resource: Some(self.user.xmpp_muc_name.clone()),
|
|
|
|
}),
|
|
|
|
id: m.id,
|
|
|
|
r#type: MessageType::Groupchat,
|
|
|
|
lang: None,
|
|
|
|
subject: None,
|
|
|
|
body: m.body.clone(),
|
|
|
|
custom: vec![],
|
|
|
|
}
|
|
|
|
.serialize(output);
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|