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;
|
2024-04-15 16:18:51 +00:00
|
|
|
|
use proto_xmpp::bind::{Jid, Name, Server};
|
2023-10-13 20:09:08 +00:00
|
|
|
|
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<()> {
|
2024-04-15 16:18:51 +00:00
|
|
|
|
match p.to {
|
|
|
|
|
None => {
|
|
|
|
|
self.self_presence(output).await;
|
2023-10-13 20:09:08 +00:00
|
|
|
|
}
|
2024-04-15 16:18:51 +00:00
|
|
|
|
Some(Jid {
|
|
|
|
|
name: Some(name),
|
|
|
|
|
server,
|
|
|
|
|
// resources in MUCs are members' personas – not implemented (yet?)
|
|
|
|
|
resource: Some(_),
|
|
|
|
|
}) if server.0 == self.hostname_rooms => {
|
|
|
|
|
self.muc_presence(name, output).await?;
|
2023-10-13 20:09:08 +00:00
|
|
|
|
}
|
2024-04-15 16:18:51 +00:00
|
|
|
|
_ => {
|
|
|
|
|
// TODO other presence cases
|
|
|
|
|
let response = Presence::<()>::default();
|
|
|
|
|
response.serialize(output);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn self_presence(&mut self, output: &mut Vec<Event<'static>>) {
|
|
|
|
|
let response = Presence::<()> {
|
|
|
|
|
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(self.user.xmpp_name.clone()),
|
|
|
|
|
server: Server(self.hostname.clone()),
|
|
|
|
|
resource: Some(self.user.xmpp_resource.clone()),
|
|
|
|
|
}),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
response.serialize(output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn muc_presence(&mut self, name: Name, output: &mut Vec<Event<'static>>) -> Result<()> {
|
|
|
|
|
let a = self.user_handle.join_room(RoomId::from(name.0.clone())?).await?;
|
|
|
|
|
// TODO handle bans
|
|
|
|
|
let response = Presence::<()> {
|
|
|
|
|
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.clone()),
|
|
|
|
|
server: Server(self.hostname_rooms.clone()),
|
|
|
|
|
resource: Some(self.user.xmpp_muc_name.clone()),
|
|
|
|
|
}),
|
|
|
|
|
..Default::default()
|
2023-10-13 20:09:08 +00:00
|
|
|
|
};
|
|
|
|
|
response.serialize(output);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|