diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index 8adc2a5f..cb5d7ef9 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -16,7 +16,7 @@ use tokio::fs::File; use tokio_util::codec::{BytesCodec, FramedRead}; pub use tokio_xmpp::parsers; use tokio_xmpp::parsers::{ - bookmarks2::Conference, + bookmarks2, caps::{compute_disco, hash_caps, Caps}, disco::{DiscoInfoQuery, DiscoInfoResult, Feature, Identity}, hashes::Algo, @@ -29,6 +29,7 @@ use tokio_xmpp::parsers::{ }, ns, presence::{Presence, Type as PresenceType}, + private::Query as PrivateXMLQuery, pubsub::pubsub::{Items, PubSub}, roster::{Item as RosterItem, Roster}, stanza_error::{DefinedCondition, ErrorType, StanzaError}, @@ -84,7 +85,7 @@ pub enum Event { #[cfg(feature = "avatars")] AvatarRetrieved(Jid, String), ChatMessage(Id, BareJid, Body), - JoinRoom(BareJid, Conference), + JoinRoom(BareJid, bookmarks2::Conference), LeaveRoom(BareJid), LeaveAllRooms, RoomJoined(BareJid), @@ -388,6 +389,18 @@ impl Agent { } else if payload.is("slot", ns::HTTP_UPLOAD) { let new_events = handle_upload_result(&from, iq.id, payload, self).await; events.extend(new_events); + } else if payload.is("query", ns::PRIVATE) { + match PrivateXMLQuery::try_from(payload) { + Ok(query) => { + for conf in query.storage.conferences { + let (jid, room) = conf.into_bookmarks2(); + events.push(Event::JoinRoom(jid, room)); + } + } + Err(e) => { + panic!("Wrong XEP-0048 v1.0 Bookmark format: {}", e); + } + } } } else if let IqType::Set(_) = iq.payload { // We MUST answer unhandled set iqs with a service-unavailable error. @@ -402,7 +415,6 @@ impl Agent { .into(); let _ = self.client.send_stanza(iq).await; } - events } diff --git a/xmpp/src/pubsub/mod.rs b/xmpp/src/pubsub/mod.rs index 167c9c22..ae6b25da 100644 --- a/xmpp/src/pubsub/mod.rs +++ b/xmpp/src/pubsub/mod.rs @@ -8,7 +8,7 @@ use super::Agent; use crate::Event; use std::str::FromStr; use tokio_xmpp::parsers::{ - bookmarks2::{Autojoin, Conference}, + bookmarks2::{self, Autojoin}, ns, pubsub::event::PubSubEvent, pubsub::pubsub::PubSub, @@ -37,7 +37,7 @@ pub(crate) async fn handle_event(from: &Jid, elem: Element, agent: &mut Agent) - let item = items.clone().pop().unwrap(); let jid = BareJid::from_str(&item.id.clone().unwrap().0).unwrap(); let payload = item.payload.clone().unwrap(); - match Conference::try_from(payload) { + match bookmarks2::Conference::try_from(payload) { Ok(conference) => { if conference.autojoin == Autojoin::True { events.push(Event::JoinRoom(jid, conference)); @@ -97,7 +97,7 @@ pub(crate) fn handle_iq_result(from: &Jid, elem: Element) -> impl IntoIterator { if let Autojoin::True = conference.autojoin { events.push(Event::JoinRoom(jid, conference));