From ba48f6de46f64aad05409e5aff439c8f10a9fbfa Mon Sep 17 00:00:00 2001 From: Werner Kroneman Date: Mon, 11 Dec 2023 13:48:39 +0100 Subject: [PATCH] Lazily bubbling the XMPP event up to the Disconnected event. --- xmpp/examples/hello_bot.rs | 4 ++-- xmpp/src/lib.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xmpp/examples/hello_bot.rs b/xmpp/examples/hello_bot.rs index 0a6a93b4..cd96d24c 100644 --- a/xmpp/examples/hello_bot.rs +++ b/xmpp/examples/hello_bot.rs @@ -39,8 +39,8 @@ async fn main() -> Result<(), Option<()>> { Event::Online => { println!("Online."); } - Event::Disconnected => { - println!("Disconnected"); + Event::Disconnected(e) => { + println!("Disconnected because of {}.", e); return Err(None); } Event::ContactAdded(contact) => { diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index 75cf9f7e..8adc2a5f 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -77,7 +77,7 @@ pub type RoomNick = String; #[derive(Debug)] pub enum Event { Online, - Disconnected, + Disconnected(Error), ContactAdded(RosterItem), ContactRemoved(RosterItem), ContactChanged(RosterItem), @@ -539,8 +539,8 @@ impl Agent { let _ = self.client.send_stanza(iq).await; } TokioXmppEvent::Online { resumed: true, .. } => {} - TokioXmppEvent::Disconnected(_) => { - events.push(Event::Disconnected); + TokioXmppEvent::Disconnected(e) => { + events.push(Event::Disconnected(e)); } TokioXmppEvent::Stanza(elem) => { if elem.is("iq", "jabber:client") { @@ -659,7 +659,7 @@ mod tests { while let Some(events) = agent.wait_for_events().await { assert!(match events[0] { - Event::Disconnected => true, + Event::Disconnected(_) => true, _ => false, }); assert_eq!(events.len(), 1);