Skip to content

Commit 03c7310

Browse files
Ppjet6linkmauve
authored andcommitted
xmpp: Stop proxying tokio-xmpp event in escape-hatch, add our own variants
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 <[email protected]>
1 parent a635d08 commit 03c7310

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

xmpp/ChangeLog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
4040
- New 'escape-hatch' feature: Allow sending tokio_xmpp::Stanza directly
4141
instead of having to go through xmpp-rs' API when it's lacking. This
4242
is meant to stay behind a feature. Also allows directly receiving
43-
TokioXmppEvent.
43+
stanzas.
4444
- Added documentation on `Event` enum.
4545
* Fixes:
4646
- Use tokio::sync::RwLock not std::sync::RwLock (!432)

xmpp/src/event.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use tokio_xmpp::jid::BareJid;
88
#[cfg(feature = "avatars")]
99
use tokio_xmpp::jid::Jid;
1010
use tokio_xmpp::parsers::roster::Item as RosterItem;
11+
#[cfg(feature = "escape-hatch")]
12+
use tokio_xmpp::parsers::{iq::Iq, message::Message, presence::Presence};
1113

1214
use crate::parsers::confirm::Confirm;
1315
use crate::{delay::StanzaTimeInfo, Error, MessageId, RoomNick};
@@ -113,5 +115,15 @@ pub enum Event {
113115
/// A file has been uploaded over HTTP; contains the URL of the file.
114116
HttpUploadedFile(String),
115117
#[cfg(feature = "escape-hatch")]
116-
TokioXmppEvent(TokioXmppEvent),
118+
/// Variant only available when the "escape-hatch" feature is enabled. Proxies an Iq received
119+
/// as a tokio-xmpp event.
120+
Iq(Iq),
121+
#[cfg(feature = "escape-hatch")]
122+
/// Variant only available when the "escape-hatch" feature is enabled. Proxies a Message
123+
/// received as a tokio-xmpp event.
124+
Message(Message),
125+
#[cfg(feature = "escape-hatch")]
126+
/// Variant only available when the "escape-hatch" feature is enabled. Proxies a Presence
127+
/// received as a tokio-xmpp event.
128+
Presence(Presence),
117129
}

xmpp/src/event_loop.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ pub async fn wait_for_events(agent: &mut Agent) -> Vec<Event> {
1717
if let Some(event) = agent.client.next().await {
1818
let mut events = Vec::new();
1919

20-
#[cfg(feature = "escape-hatch")]
21-
events.push(Event::TokioXmppEvent(event.clone()));
22-
2320
match event {
2421
TokioXmppEvent::Online { resumed: false, .. } => {
2522
let presence =
@@ -47,14 +44,23 @@ pub async fn wait_for_events(agent: &mut Agent) -> Vec<Event> {
4744
events.push(Event::Disconnected(e));
4845
}
4946
TokioXmppEvent::Stanza(Stanza::Iq(iq)) => {
47+
#[cfg(feature = "escape-hatch")]
48+
events.push(Event::Iq(iq.clone()));
49+
5050
let new_events = iq::handle_iq(agent, iq).await;
5151
events.extend(new_events);
5252
}
5353
TokioXmppEvent::Stanza(Stanza::Message(message)) => {
54+
#[cfg(feature = "escape-hatch")]
55+
events.push(Event::Message(message.clone()));
56+
5457
let new_events = message::receive::handle_message(agent, message).await;
5558
events.extend(new_events);
5659
}
5760
TokioXmppEvent::Stanza(Stanza::Presence(presence)) => {
61+
#[cfg(feature = "escape-hatch")]
62+
events.push(Event::Presence(presence.clone()));
63+
5864
let new_events = presence::receive::handle_presence(agent, presence).await;
5965
events.extend(new_events);
6066
}

0 commit comments

Comments
 (0)