Receive legacy XEP-0048 v1.0 bookmarks

This commit is contained in:
xmppftw 2023-12-16 16:06:38 +01:00 committed by Emmanuel Gil Peyrot
parent f9b71c8da0
commit 5fbba5c925
2 changed files with 18 additions and 6 deletions

View file

@ -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
}

View file

@ -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<I
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) {
match bookmarks2::Conference::try_from(payload) {
Ok(conference) => {
if let Autojoin::True = conference.autojoin {
events.push(Event::JoinRoom(jid, conference));