lavina/crates/projection-xmpp/src/updates.rs

47 lines
1.5 KiB
Rust
Raw Normal View History

//! 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);
}
_ => {}
}
Ok(())
}
}