2023-10-13 20:09:08 +00:00
|
|
|
//! 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,
|
|
|
|
} => {
|
|
|
|
Message::<()> {
|
|
|
|
to: Some(Jid {
|
|
|
|
name: Some(self.user.xmpp_name.clone()),
|
2024-04-15 00:33:26 +00:00
|
|
|
server: Server(self.hostname.clone()),
|
2023-10-13 20:09:08 +00:00
|
|
|
resource: Some(self.user.xmpp_resource.clone()),
|
|
|
|
}),
|
|
|
|
from: Some(Jid {
|
|
|
|
name: Some(Name(room_id.into_inner().into())),
|
2024-04-15 00:33:26 +00:00
|
|
|
server: Server(self.hostname_rooms.clone()),
|
2023-10-13 20:09:08 +00:00
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|