Refactor online awaiting to separate function
[?]
Oct 30, 2018, 11:09 AM
H5FNCGYJ27RKRBFSGTUXTBN2TA5AMIDTDLEOVCD2T2FPIRSTWH5ACDependencies
- [2]
34NQKMVKDon't move XmppConnection everywhere - [3]
F5UQL2FBManage xmpp connection in cmd processing loop - [4]
E4YEIQYOConnect to xmpp server - [5]
AXDOLAOAIntroduce xmpp client - [*]
AVBHYHOAStop xmpp thread by shudown
Change contents
- replacement in src/xmpp.rs at line 45[3.1084]→[3.1084:2255](∅→∅),[3.1084]→[3.1084:2255](∅→∅),[3.2255]→[2.330:431](∅→∅),[2.431]→[3.2596:2775](∅→∅),[3.2596]→[3.2596:2775](∅→∅),[3.2775]→[2.432:529](∅→∅),[2.529]→[3.3092:3191](∅→∅),[3.3092]→[3.3092:3191](∅→∅)
let (sink, stream) = client.split();Box::new(future::loop_fn((sink, stream, account),|(sink, stream, account)| {stream.into_future().then(|r| match r {Ok((event, stream)) => match event {Some(Event::Online) => {info!("Online");future::ok(future::Loop::Break(future::Loop::Break(XmppConnection {account,inner: Some((sink, stream)),},)))}Some(Event::Stanza(s)) => {info!("xmpp stanza: {:?}", s);future::ok(future::Loop::Continue((sink, stream, account)))}_ => {warn!("Disconnected");future::ok(future::Loop::Break(future::Loop::Continue(account)))}},Err((e, _)) => {error!("xmpp receive error: {}", e);future::ok(future::Loop::Break(future::Loop::Continue(account)))}})},))Self::online(client.split(), account).then(|r| match r {Ok(conn) => future::ok(future::Loop::Break(conn)),Err(acc) => future::ok(future::Loop::Continue(acc)),}) - edit in src/xmpp.rs at line 51
}/// get connection and wait for online status and set presence/// returns error if something went wrongfn online((sink, stream): (stream::SplitSink<Client>, stream::SplitStream<Client>),account: config::Account,) -> impl Future<Item = XmppConnection, Error = config::Account> {Box::new(future::loop_fn((sink, stream, account),|(sink, stream, account)| {stream.into_future().then(|r| match r {Ok((event, stream)) => match event {Some(Event::Online) => {info!("Online");future::ok(future::Loop::Break(XmppConnection {account,inner: Some((sink, stream)),}))}Some(Event::Stanza(s)) => {info!("xmpp stanza: {:?}", s);future::ok(future::Loop::Continue((sink, stream, account)))}_ => {warn!("Disconnected");future::err(account)}},Err((e, _)) => {error!("xmpp receive error: {}", e);future::err(account)}})},))