Create separate functions to process incoming XMPP stanzas

[?]
Dec 29, 2018, 6:30 PM
2L3JHRULRLBHT4K2VE4MHKDFX5RJXYUDTJJCLTUYH3DOOVCJT6WAC

Dependencies

Change contents

  • replacement in src/xmpp/mod.rs at line 74
    [3.1168][3.1875:1988](),[3.1875][3.1875:1988](),[3.1988][2.0:533]()
    /// get connection and wait for online status and set presence
    /// returns error if something went wrong
    fn online(self) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>> {
    future::loop_fn((self.inner, self.account), |(client, account)| {
    client.into_future().then(|r| match r {
    Ok((event, client)) => match event {
    Some(Event::Online) => {
    info!("Online");
    future::ok(future::Loop::Break(XmppConnection {
    account,
    inner: client,
    }))
    [3.1168]
    [2.533]
    /// base XMPP processing
    fn xmpp_processing(&mut self, event: &Event) {}
    /// process event from xmpp stream
    /// returns from future when condition met
    /// or stop future was resolved
    fn processing<S, F, T, E>(
    self,
    stop_condition: S,
    stop_future: F,
    ) -> impl Future<
    Item = (Self, Result<Either<F, T>, E>),
    Error = (std::rc::Rc<config::Account>, Result<Either<F, T>, E>),
    >
    where
    F: Future<Item = T, Error = E>,
    S: FnMut(&mut Self, &Event) -> bool,
    {
    future::loop_fn(
    (self, stop_future, stop_condition),
    |(xmpp, stop_future, mut stop_condition)| {
    let XmppConnection { inner, account } = xmpp;
    inner.into_future().select2(stop_future).then(|r| match r {
    Ok(Either::A(((event, client), b))) => {
    if let Some(event) = event {
    let mut xmpp = XmppConnection {
    inner: client,
    account,
    };
    xmpp.xmpp_processing(&event);
    if stop_condition(&mut xmpp, &event) {
    future::ok(future::Loop::Break((xmpp, Ok(Either::A(b)))))
    } else {
    future::ok(future::Loop::Continue((xmpp, b, stop_condition)))
    }
    } else {
    future::err((account, Ok(Either::A(b))))
    }
  • replacement in src/xmpp/mod.rs at line 113
    [2.555][2.555:736]()
    Some(Event::Stanza(s)) => {
    info!("xmpp stanza: {:?}", s);
    future::ok(future::Loop::Continue((client, account)))
    [2.555]
    [2.736]
    Ok(Either::B((t, a))) => {
    if let Some(inner) = a.into_inner() {
    future::ok(future::Loop::Break((
    XmppConnection { inner, account },
    Ok(Either::B(t)),
    )))
    } else {
    future::err((account, Ok(Either::B(t))))
    }
  • replacement in src/xmpp/mod.rs at line 123
    [2.758][2.758:832]()
    _ => {
    warn!("Disconnected");
    [2.758]
    [3.3237]
    Err(Either::A((_e, b))) => future::err((account, Ok(Either::A(b)))),
    Err(Either::B((e, a))) => {
    if let Some(inner) = a.into_inner() {
    future::ok(future::Loop::Break((
    XmppConnection { inner, account },
    Err(e),
    )))
    } else {
    future::err((account, Err(e)))
    }
    }
    })
    },
    )
    }
    /// get connection and wait for online status and set presence
    /// returns error if something went wrong
    fn online(self) -> impl Future<Item = XmppConnection, Error = std::rc::Rc<config::Account>> {
    Box::new(future::loop_fn(
    (self.inner, self.account),
    |(client, account)| {
    client.into_future().then(|r| match r {
    Ok((event, client)) => match event {
    Some(Event::Online) => {
    info!("Online");
    future::ok(future::Loop::Break(XmppConnection {
    account,
    inner: client,
    }))
    }
    Some(Event::Stanza(s)) => {
    info!("xmpp stanza: {:?}", s);
    future::ok(future::Loop::Continue((client, account)))
    }
    _ => {
    warn!("Disconnected");
    future::err(account)
    }
    },
    Err((e, _)) => {
    error!("xmpp receive error: {}", e);
  • replacement in src/xmpp/mod.rs at line 167
    [3.3304][2.833:1027]()
    },
    Err((e, _)) => {
    error!("xmpp receive error: {}", e);
    future::err(account)
    }
    })
    })
    [3.3304]
    [3.3349]
    })
    },
    ))