forked from lavina/lavina
75 lines
2.6 KiB
Rust
75 lines
2.6 KiB
Rust
//! Handling of updates and converting them into server2client stanzas
|
|
|
|
use anyhow::Result;
|
|
use quick_xml::events::Event;
|
|
|
|
use lavina_core::player::Updates;
|
|
use proto_xmpp::bind::{Jid, Name, Resource, Server};
|
|
use proto_xmpp::client::{Message, MessageType};
|
|
use proto_xmpp::xml::ToXml;
|
|
|
|
use crate::XmppConnection;
|
|
|
|
impl<'a> XmppConnection<'a> {
|
|
pub async fn handle_update(&mut self, output: &mut Vec<Event<'static>>, update: Updates) -> Result<()> {
|
|
match update {
|
|
Updates::NewMessage {
|
|
room_id,
|
|
author_id,
|
|
body,
|
|
created_at: _,
|
|
} => {
|
|
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(room_id.into_inner().into())),
|
|
server: Server(self.hostname_rooms.clone()),
|
|
resource: Some(Resource(author_id.into_inner().into())),
|
|
}),
|
|
id: None,
|
|
r#type: MessageType::Groupchat,
|
|
lang: None,
|
|
subject: None,
|
|
body: body.into(),
|
|
custom: vec![],
|
|
}
|
|
.serialize(output);
|
|
}
|
|
Updates::NewDialogMessage {
|
|
sender,
|
|
receiver,
|
|
body,
|
|
created_at: _,
|
|
} => {
|
|
if receiver == self.user.player_id {
|
|
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(sender.as_inner().clone())),
|
|
server: Server(self.hostname.clone()),
|
|
resource: Some(Resource(sender.into_inner())),
|
|
}),
|
|
id: None,
|
|
r#type: MessageType::Chat,
|
|
lang: None,
|
|
subject: None,
|
|
body: body.into(),
|
|
custom: vec![],
|
|
}
|
|
.serialize(output);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|