Create separate functions to process incoming XMPP stanzas
[?]
Dec 29, 2018, 6:30 PM
2L3JHRULRLBHT4K2VE4MHKDFX5RJXYUDTJJCLTUYH3DOOVCJT6WACDependencies
- [2]
FDHRCKH5Unneded Box - [3]
O2GM5J4FDon't split xmpp receiving and sending - [4]
VS6AHRWIMove XMPP to separate dir - [5]
OGMBXBKPMove online to XmppConnection - [6]
NDDQQP2PUpdate deps
Change contents
- replacement in src/xmpp/mod.rs at line 74
/// get connection and wait for online status and set presence/// returns error if something went wrongfn 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,}))/// base XMPP processingfn xmpp_processing(&mut self, event: &Event) {}/// process event from xmpp stream/// returns from future when condition met/// or stop future was resolvedfn 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>),>whereF: 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
Some(Event::Stanza(s)) => {info!("xmpp stanza: {:?}", s);future::ok(future::Loop::Continue((client, account)))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
_ => {warn!("Disconnected");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 wrongfn 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
},Err((e, _)) => {error!("xmpp receive error: {}", e);future::err(account)}})})})},))