use tokio_xmpp::connect::ServerConnector;
use tokio_xmpp::{
jid::Jid,
parsers::{
bookmarks,
disco::DiscoInfoResult,
iq::Iq,
ns,
private::Query as PrivateXMLQuery,
pubsub::pubsub::{Items, PubSub},
},
};
use crate::Agent;
pub async fn handle_disco_info_result<C: ServerConnector>(
agent: &mut Agent<C>,
disco: DiscoInfoResult,
from: Jid,
) {
if from == agent.client.bound_jid().unwrap().to_bare() && agent.awaiting_disco_bookmarks_type {
info!("Received disco info about bookmarks type");
agent.awaiting_disco_bookmarks_type = false;
let mut perform_bookmarks2 = false;
info!("{:#?}", disco.features);
for feature in disco.features {
if feature.var == "urn:xmpp:bookmarks:1#compat" {
perform_bookmarks2 = true;
}
}
if perform_bookmarks2 {
let iq = Iq::from_get("bookmarks", PubSub::Items(Items::new(ns::BOOKMARKS2))).into();
let _ = agent.client.send_stanza(iq).await;
} else {
let iq = Iq::from_get(
"bookmarks-legacy",
PrivateXMLQuery {
storage: bookmarks::Storage::new(),
},
)
.into();
let _ = agent.client.send_stanza(iq).await;
}
} else {
unimplemented!("Ignored disco#info response from {}", from);
}
}