forked from lavina/lavina
58 lines
2.1 KiB
Rust
58 lines
2.1 KiB
Rust
//! Handling of all client2server message stanzas
|
|
|
|
use lavina_core::player::PlayerId;
|
|
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> {
|
|
#[tracing::instrument(skip(self, output, m), name = "XmppConnection::message")]
|
|
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() == &*self.hostname_rooms && m.r#type == MessageType::Groupchat {
|
|
let Some(body) = &m.body else { return Ok(()) };
|
|
self.user_handle.send_message(RoomId::try_from(name.0.clone())?, body.clone()).await?;
|
|
Message::<()> {
|
|
to: Some(Jid {
|
|
name: Some(self.user.xmpp_name.clone()),
|
|
server: Server(self.hostname.clone()),
|
|
resource: Some(self.user.xmpp_resource.clone()),
|
|
}),
|
|
from: Some(Jid {
|
|
name: Some(name),
|
|
server: Server(self.hostname_rooms.clone()),
|
|
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 if server.0.as_ref() == &*self.hostname && m.r#type == MessageType::Chat {
|
|
let Some(body) = &m.body else { return Ok(()) };
|
|
self.user_handle.send_dialog_message(PlayerId::from(name.0.clone())?, body.clone()).await?;
|
|
Ok(())
|
|
} else {
|
|
todo!()
|
|
}
|
|
} else {
|
|
todo!()
|
|
}
|
|
}
|
|
}
|