From 03c7310990603f52cfb0124af393e2f630c34db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 10 Sep 2025 12:05:19 +0200 Subject: [PATCH] xmpp: Stop proxying tokio-xmpp event in escape-hatch, add our own variants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was causing issues with Clone-ing tokio-xmpp Event-s as they include Error-s which are typically not Clone-able. Event and Stanza aren't Clone-able either so might as well do our own stuff here. Signed-off-by: Maxime “pep” Buquet --- xmpp/ChangeLog | 2 +- xmpp/src/event.rs | 14 +++++++++++++- xmpp/src/event_loop.rs | 12 +++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/xmpp/ChangeLog b/xmpp/ChangeLog index a479ac31976590490762627d27fbda9c8905afdd..a16939a3b67823df8e6395ccce4042ccf6dc3589 100644 --- a/xmpp/ChangeLog +++ b/xmpp/ChangeLog @@ -40,7 +40,7 @@ XXXX-YY-ZZ [ RELEASER ] - New 'escape-hatch' feature: Allow sending tokio_xmpp::Stanza directly instead of having to go through xmpp-rs' API when it's lacking. This is meant to stay behind a feature. Also allows directly receiving - TokioXmppEvent. + stanzas. - Added documentation on `Event` enum. * Fixes: - Use tokio::sync::RwLock not std::sync::RwLock (!432) diff --git a/xmpp/src/event.rs b/xmpp/src/event.rs index 32f5db22e20151445af1a43d7608b18f0a5987c9..282aabc116e6dbccafa85fab5bb5a66b039e5548 100644 --- a/xmpp/src/event.rs +++ b/xmpp/src/event.rs @@ -8,6 +8,8 @@ use tokio_xmpp::jid::BareJid; #[cfg(feature = "avatars")] use tokio_xmpp::jid::Jid; use tokio_xmpp::parsers::roster::Item as RosterItem; +#[cfg(feature = "escape-hatch")] +use tokio_xmpp::parsers::{iq::Iq, message::Message, presence::Presence}; use crate::parsers::confirm::Confirm; use crate::{delay::StanzaTimeInfo, Error, MessageId, RoomNick}; @@ -113,5 +115,15 @@ pub enum Event { /// A file has been uploaded over HTTP; contains the URL of the file. HttpUploadedFile(String), #[cfg(feature = "escape-hatch")] - TokioXmppEvent(TokioXmppEvent), + /// Variant only available when the "escape-hatch" feature is enabled. Proxies an Iq received + /// as a tokio-xmpp event. + Iq(Iq), + #[cfg(feature = "escape-hatch")] + /// Variant only available when the "escape-hatch" feature is enabled. Proxies a Message + /// received as a tokio-xmpp event. + Message(Message), + #[cfg(feature = "escape-hatch")] + /// Variant only available when the "escape-hatch" feature is enabled. Proxies a Presence + /// received as a tokio-xmpp event. + Presence(Presence), } diff --git a/xmpp/src/event_loop.rs b/xmpp/src/event_loop.rs index cced3ab2f4abfadc4c82f473005b32b6c2e7a918..54f2fc362eb0f589052a865e42a7ffa624082f50 100644 --- a/xmpp/src/event_loop.rs +++ b/xmpp/src/event_loop.rs @@ -17,9 +17,6 @@ pub async fn wait_for_events(agent: &mut Agent) -> Vec { if let Some(event) = agent.client.next().await { let mut events = Vec::new(); - #[cfg(feature = "escape-hatch")] - events.push(Event::TokioXmppEvent(event.clone())); - match event { TokioXmppEvent::Online { resumed: false, .. } => { let presence = @@ -47,14 +44,23 @@ pub async fn wait_for_events(agent: &mut Agent) -> Vec { events.push(Event::Disconnected(e)); } TokioXmppEvent::Stanza(Stanza::Iq(iq)) => { + #[cfg(feature = "escape-hatch")] + events.push(Event::Iq(iq.clone())); + let new_events = iq::handle_iq(agent, iq).await; events.extend(new_events); } TokioXmppEvent::Stanza(Stanza::Message(message)) => { + #[cfg(feature = "escape-hatch")] + events.push(Event::Message(message.clone())); + let new_events = message::receive::handle_message(agent, message).await; events.extend(new_events); } TokioXmppEvent::Stanza(Stanza::Presence(presence)) => { + #[cfg(feature = "escape-hatch")] + events.push(Event::Presence(presence.clone())); + let new_events = presence::receive::handle_presence(agent, presence).await; events.extend(new_events); }