∅:D[
3.1168] → [
4.1875:1988]
∅:D[
4.1875] → [
4.1875:1988]
/// 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,
}))
/// 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))))
}