SA2IOFGYAOWEAS2M3QUXAIUZ5PRGXLQLDYCF2JQKCBGN42K6XU6AC
UAT5MV5OUZS4UW3ZOEMNG75WZOS6W4274FI6F65GQX3TH7KWSCXQC
FV6BJ5K64QG63YI2PTII44ZEBAYNJBQZ5FSBHW65EPHGBKFGUW4AC
BWDUANCV77MCLCYMRS2UNFIFW4ZC3KB2KEGEUI77FRO7KW6TUZJQC
CBWCXUZZBPQYFROVZFCIWHW3CPNAGXO3PUARLGOF4DUF6VVCYKVQC
VS6AHRWIPIMQNQAFX7INQGSUB72OW2K6HM6NGOV76RBRF6COQFRQC
EBETRYK7RNRATWD75LTFUTPF6M6KB6YPKTQUX4K232JB6CKVOZOQC
}
pub fn make_add_roster(id: &str, jid: jid::Jid) -> Element {
let mut add_roster = Iq::from_set(Roster {
items: vec![Item {
jid,
name: None,
subscription: xmpp_parsers::roster::Subscription::None,
groups: vec![],
}],
ver: None,
});
add_roster.id = Some(id.to_string());
add_roster.into()
info!("Incoming xmpp event: {:?}", event);
future::ok(self)
match event {
Event::Stanza(stanza) => {
info!("Incoming xmpp event: {:?}", stanza);
let stanza = stanza.clone();
use try_from::TryInto;
if let Some(iq) = stanza.try_into().ok() as Option<xmpp_parsers::iq::Iq> {
if let Some(id) = iq.id {
if let Some((_, (jid, _message))) =
self.state.data.pending_add_roster_ids.remove_entry(&id)
{
if let xmpp_parsers::iq::IqType::Result(None) = iq.payload {
info!("Jid {} added to roster", jid);
}
}
}
if let xmpp_parsers::iq::IqType::Set(element) = iq.payload {
if let Some(roster) =
element.try_into().ok() as Option<xmpp_parsers::roster::Roster>
{
self.state
.data
.roster
.extend(roster.items.into_iter().map(|i| {
info!("Add {} to roster", i.jid);
(i.jid, ())
}));
}
}
}
future::ok(self)
}
Event::Online => future::ok(self),
e => {
warn!("Unexpected event {:?}", e);
future::err(self.account)
}
}
let XmppConnection {
account,
state: XmppState { client, mut data },
} = self;
data.counter += 1;
let id_add_roster = format!("id_add_roster{}", data.counter);
let add_roster = stanzas::make_add_roster(&id_add_roster, cmd.xmpp_to.clone());
let account2 = account.clone();
info!("Adding jid to roster... {:?}", add_roster);
use tokio::prelude::Sink;
Box::new(
client
.send(add_roster)
.map_err(|e| {
error!("Error on send adding to roster: {}", e);
account2
})
.and_then(move |client| {
data.pending_add_roster_ids
.insert(id_add_roster, (cmd.xmpp_to, cmd.message));
future::ok(XmppConnection {
account,
state: XmppState { client, data },
})
}),
)