Lazily bubbling the XMPP event up to the Disconnected event.

This commit is contained in:
Werner Kroneman 2023-12-11 13:48:39 +01:00 committed by pep
parent 8f18cf2208
commit ba48f6de46
2 changed files with 6 additions and 6 deletions

View file

@ -39,8 +39,8 @@ async fn main() -> Result<(), Option<()>> {
Event::Online => { Event::Online => {
println!("Online."); println!("Online.");
} }
Event::Disconnected => { Event::Disconnected(e) => {
println!("Disconnected"); println!("Disconnected because of {}.", e);
return Err(None); return Err(None);
} }
Event::ContactAdded(contact) => { Event::ContactAdded(contact) => {

View file

@ -77,7 +77,7 @@ pub type RoomNick = String;
#[derive(Debug)] #[derive(Debug)]
pub enum Event { pub enum Event {
Online, Online,
Disconnected, Disconnected(Error),
ContactAdded(RosterItem), ContactAdded(RosterItem),
ContactRemoved(RosterItem), ContactRemoved(RosterItem),
ContactChanged(RosterItem), ContactChanged(RosterItem),
@ -539,8 +539,8 @@ impl Agent {
let _ = self.client.send_stanza(iq).await; let _ = self.client.send_stanza(iq).await;
} }
TokioXmppEvent::Online { resumed: true, .. } => {} TokioXmppEvent::Online { resumed: true, .. } => {}
TokioXmppEvent::Disconnected(_) => { TokioXmppEvent::Disconnected(e) => {
events.push(Event::Disconnected); events.push(Event::Disconnected(e));
} }
TokioXmppEvent::Stanza(elem) => { TokioXmppEvent::Stanza(elem) => {
if elem.is("iq", "jabber:client") { if elem.is("iq", "jabber:client") {
@ -659,7 +659,7 @@ mod tests {
while let Some(events) = agent.wait_for_events().await { while let Some(events) = agent.wait_for_events().await {
assert!(match events[0] { assert!(match events[0] {
Event::Disconnected => true, Event::Disconnected(_) => true,
_ => false, _ => false,
}); });
assert_eq!(events.len(), 1); assert_eq!(events.len(), 1);