forked from lavina/lavina
56 lines
1.9 KiB
Rust
56 lines
1.9 KiB
Rust
//! 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()),
|
|
server: Server("localhost".into()),
|
|
resource: Some(self.user.xmpp_resource.clone()),
|
|
}),
|
|
from: Some(Jid {
|
|
name: Some(self.user.xmpp_name.clone()),
|
|
server: Server("localhost".into()),
|
|
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()),
|
|
server: Server("localhost".into()),
|
|
resource: Some(self.user.xmpp_resource.clone()),
|
|
}),
|
|
from: Some(Jid {
|
|
name: Some(name.clone()),
|
|
server: Server("rooms.localhost".into()),
|
|
resource: Some(self.user.xmpp_muc_name.clone()),
|
|
}),
|
|
..Default::default()
|
|
}
|
|
} else {
|
|
Presence::<()>::default()
|
|
};
|
|
response.serialize(output);
|
|
Ok(())
|
|
}
|
|
}
|