}
fn process_jid(&mut self, xmpp_to: &xmpp_parsers::Jid) {
if let Some(ref mut mailbox) = self.state.data.outgoing_mailbox.get_mut(xmpp_to) {
if !mailbox.is_empty() {
if let Some(ref mut rdata) = self.state.data.roster.get_mut(&xmpp_to.clone().into())
{
info!("Jid {} in roster", xmpp_to);
let sub_to = match rdata.0 {
xmpp_parsers::roster::Subscription::To => true,
xmpp_parsers::roster::Subscription::Both => true,
_ => false,
};
if sub_to {
info!("Subscribed to {}", xmpp_to);
self.state.data.send_queue.extend(
mailbox.drain(..).map(|message| {
stanzas::make_chat_message(xmpp_to.clone(), message)
}),
);
} else if rdata.1 == xmpp_parsers::roster::Ask::None {
info!("Not subscribed to {}", xmpp_to);
self.state.data.counter += 1;
let id_ask_subscribe =
format!("id_ask_subscribe{}", self.state.data.counter);
self.state
.data
.send_queue
.push_back(stanzas::make_ask_subscribe(
id_ask_subscribe,
xmpp_to.clone(),
));
}
let sub_from = match rdata.0 {
xmpp_parsers::roster::Subscription::From => true,
xmpp_parsers::roster::Subscription::Both => true,
_ => false,
};
if !sub_from {
info!("Not subscription from {}", xmpp_to);
self.state.data.counter += 1;
let id_allow_subscribe =
format!("id_allow_subscribe{}", self.state.data.counter);
self.state
.data
.send_queue
.push_back(stanzas::make_allow_subscribe(
id_allow_subscribe,
xmpp_to.clone(),
));
}
} else {
info!("Jid {} not in roster", xmpp_to);
self.state.data.counter += 1;
let id_add_roster = format!("id_add_roster{}", self.state.data.counter);
let add_roster =
stanzas::make_add_roster(&id_add_roster, xmpp_to.clone().into());
info!("Adding jid {} to roster id {}", xmpp_to, id_add_roster);
self.state.data.pending_ids.insert(
id_add_roster,
IqWait::new(
60,
AddRosterIqHandler {
jid: xmpp_to.clone().into(),
},
),
);
self.state.data.send_queue.push_back(add_roster);
}
}
}