2023-10-13 20:09:08 +00:00
|
|
|
//! Handling of all client2server presence 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::Presence;
|
|
|
|
use proto_xmpp::xml::{Ignore, ToXml};
|
|
|
|
|
|
|
|
use crate::XmppConnection;
|
|
|
|
|
|
|
|
impl<'a> XmppConnection<'a> {
|
|
|
|
pub async fn handle_presence(&mut self, output: &mut Vec<Event<'static>>, p: Presence<Ignore>) -> Result<()> {
|
|
|
|
let response = if p.to.is_none() {
|
|
|
|
Presence::<()> {
|
|
|
|
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(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()),
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
} else if let Some(Jid {
|
|
|
|
name: Some(name),
|
|
|
|
server,
|
|
|
|
resource: Some(resource),
|
|
|
|
}) = p.to
|
|
|
|
{
|
|
|
|
let a = self.user_handle.join_room(RoomId::from(name.0.clone())?).await?;
|
|
|
|
Presence::<()> {
|
|
|
|
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.clone()),
|
2024-04-15 00:33:26 +00:00
|
|
|
server: Server(self.hostname_rooms.clone()),
|
2023-10-13 20:09:08 +00:00
|
|
|
resource: Some(self.user.xmpp_muc_name.clone()),
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Presence::<()>::default()
|
|
|
|
};
|
|
|
|
response.serialize(output);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|