diff --git a/src/lib.rs b/src/lib.rs index 521c53f..dfd9838 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,6 +64,7 @@ impl ToString for ClientType { #[derive(PartialEq)] pub enum ClientFeature { + #[cfg(feature = "avatars")] Avatars, ContactList, JoinRooms, @@ -76,6 +77,7 @@ pub enum Event { ContactAdded(RosterItem), ContactRemoved(RosterItem), ContactChanged(RosterItem), + #[cfg(feature = "avatars")] AvatarRetrieved(Jid, String), JoinRoom(BareJid, Conference), LeaveRoom(BareJid), @@ -132,8 +134,11 @@ impl ClientBuilder<'_> { let mut features = vec![ Feature::new(ns::DISCO_INFO), ]; - if self.features.contains(&ClientFeature::Avatars) { - features.push(Feature::new(format!("{}+notify", ns::AVATAR_METADATA))); + #[cfg(feature = "avatars")] + { + if self.features.contains(&ClientFeature::Avatars) { + features.push(Feature::new(format!("{}+notify", ns::AVATAR_METADATA))); + } } if self.features.contains(&ClientFeature::JoinRooms) { features.push(Feature::new(format!("{}+notify", ns::BOOKMARKS2))); diff --git a/src/pubsub/mod.rs b/src/pubsub/mod.rs index 683179d..6ab5f0b 100644 --- a/src/pubsub/mod.rs +++ b/src/pubsub/mod.rs @@ -21,6 +21,7 @@ use xmpp_parsers::{ pubsub::pubsub::PubSub, }; +#[cfg(feature = "avatars")] pub(crate) mod avatar; pub(crate) fn handle_event(from: &Jid, elem: Element, mut tx: &mut mpsc::UnboundedSender) -> impl IntoIterator { @@ -28,6 +29,7 @@ pub(crate) fn handle_event(from: &Jid, elem: Element, mut tx: &mut mpsc::Unbound match PubSubEvent::try_from(elem) { Ok(PubSubEvent::PublishedItems { node, items }) => { match node.0 { + #[cfg(feature = "avatars")] node if node == ns::AVATAR_METADATA => { let new_events = avatar::handle_metadata_pubsub_event(&from, &mut tx, items); events.extend(new_events); @@ -82,24 +84,29 @@ pub(crate) fn handle_iq_result(from: &Jid, elem: Element) -> impl IntoIterator { - if let Autojoin::True = conference.autojoin { - events.push(Event::JoinRoom(jid, conference)); - } - }, - Err(err) => panic!("Wrong payload type in bookmarks 2 item: {}", err), + match items.node.0.clone() { + #[cfg(feature = "avatars")] + node if node == ns::AVATAR_DATA => { + let new_events = avatar::handle_data_pubsub_iq(&from, &items); + events.extend(new_events); + }, + node if node == ns::BOOKMARKS2 => { + events.push(Event::LeaveAllRooms); + for item in items.items { + let item = item.0; + let jid = BareJid::from_str(&item.id.clone().unwrap().0).unwrap(); + let payload = item.payload.clone().unwrap(); + match Conference::try_from(payload) { + Ok(conference) => { + if let Autojoin::True = conference.autojoin { + events.push(Event::JoinRoom(jid, conference)); + } + }, + Err(err) => panic!("Wrong payload type in bookmarks 2 item: {}", err), + } } - } + }, + _ => unimplemented!() } } events