Use new processing code to wait online

[?]
Dec 29, 2018, 8:56 PM
H7R7Y3FQHYR44R65YLHUAL6SSSFEMLDJTKBXMG6M7N6GDMHEDYNQC

Dependencies

  • [2] XGP44R5H Rework stopping xmpp connection
  • [3] OGMBXBKP Move online to XmppConnection
  • [4] X6L47BHQ Use different structure for established xmpp connection
  • [5] 2L3JHRUL Create separate functions to process incoming XMPP stanzas
  • [6] FDHRCKH5 Unneded Box
  • [7] AGIW6YR3 Use shared future for signal everywhere
  • [8] O2GM5J4F Don't split xmpp receiving and sending
  • [9] VS6AHRWI Move XMPP to separate dir
  • [10] NDDQQP2P Update deps

Change contents

  • replacement in src/xmpp/mod.rs at line 44
    [2.535][2.535:572]()
    F: future::Future + 'static,
    [2.535]
    [2.572]
    F: future::Future + Clone + 'static,
  • edit in src/xmpp/mod.rs at line 56
    [2.820]
    [2.820]
    .clone()
  • replacement in src/xmpp/mod.rs at line 58
    [2.850][2.850:911]()
    future::loop_fn(account, |account| {
    [2.850]
    [2.911]
    future::loop_fn(account, move |account| {
  • replacement in src/xmpp/mod.rs at line 73
    [2.1714][2.1714:1764]()
    .online()
    [2.1714]
    [2.1764]
    .processing(XmppConnection::online, stop_future.clone())
    .map(|(xmpp, _)| xmpp)
    .map_err(|(acc, _)| acc)
  • replacement in src/xmpp/mod.rs at line 114
    [2.3238][2.3238:3359]()
    Item = (Self, Result<Either<F, T>, E>),
    Error = (std::rc::Rc<config::Account>, Result<Either<F, T>, E>),
    [2.3238]
    [2.3359]
    Item = (Self, Result<Either<F, T>, failure::Error>),
    Error = (
    std::rc::Rc<config::Account>,
    Result<Either<F, T>, failure::Error>,
    ),
  • replacement in src/xmpp/mod.rs at line 122
    [2.3415][2.3415:3460]()
    S: FnMut(&mut Self, &Event) -> bool,
    [2.3415]
    [2.3460]
    E: Into<failure::Error>,
    S: FnMut(&mut Self, &Event) -> Result<bool, failure::Error>,
  • replacement in src/xmpp/mod.rs at line 137
    [2.4085][2.4085:4373]()
    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)))
    [2.4085]
    [2.4373]
    match stop_condition(&mut xmpp, &event) {
    Ok(true) => {
    future::ok(future::Loop::Break((xmpp, Ok(Either::A(b)))))
    }
    Ok(false) => {
    future::ok(future::Loop::Continue((xmpp, b, stop_condition)))
    }
    Err(e) => future::err((xmpp.account, Err(e))),
  • replacement in src/xmpp/mod.rs at line 165
    [2.5349][2.5349:5389]()
    Err(e),
    [2.5349]
    [2.5389]
    Err(e.into()),
  • replacement in src/xmpp/mod.rs at line 168
    [2.5454][2.5454:5513]()
    future::err((account, Err(e)))
    [2.5454]
    [2.5513]
    future::err((account, Err(e.into())))
  • replacement in src/xmpp/mod.rs at line 178
    [3.2767][2.5606:5704](),[2.5704][3.2865:2899](),[3.860][3.2865:2899](),[3.2865][3.2865:2899](),[3.2899][2.5705:5892](),[2.5892][3.3086:3180](),[3.1051][3.3086:3180](),[3.3086][3.3086:3180](),[3.3180][2.5893:5969](),[2.5969][3.3256:3297](),[3.1133][3.3256:3297](),[3.3256][3.3256:3297](),[3.3297][2.5970:6017](),[2.6017][3.3344:3513](),[3.1195][3.3344:3513](),[3.3344][3.3344:3513](),[3.3513][2.6018:6100](),[2.6100][3.3595:3899](),[3.1284][3.3595:3899](),[3.3595][3.3595:3899](),[3.3899][3.3237:3304](),[3.832][3.3237:3304](),[3.1796][3.3237:3304](),[3.864][3.3237:3304](),[3.3237][3.3237:3304](),[3.3304][3.3900:3945]()
    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);
    future::err(account)
    }
    })
    },
    ))
    [3.2767]
    [3.3349]
    fn online(&mut self, event: &Event) -> Result<bool, failure::Error> {
    match event {
    Event::Online => {
    info!("Online!");
    Ok(true)
    }
    Event::Stanza(s) => {
    warn!("Stanza before online: {:?}", s);
    Ok(false)
    }
    _ => {
    error!("Disconnected while online");
    Err(format_err!("Disconnected while online"))
    }
    }