Make avatar support optional.

This commit is contained in:
Emmanuel Gil Peyrot 2019-09-29 04:02:32 +02:00
parent a3e6ef8c3a
commit 598bbdd523
2 changed files with 31 additions and 19 deletions

View file

@ -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)));

View file

@ -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<Packet>) -> impl IntoIterator<Item = Event> {
@ -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<I
let mut events = Vec::new();
let pubsub = PubSub::try_from(elem).unwrap();
if let PubSub::Items(items) = pubsub {
if items.node.0 == ns::AVATAR_DATA {
let new_events = avatar::handle_data_pubsub_iq(&from, &items);
events.extend(new_events);
} else if items.node.0 == 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),
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