});
xmppSession.addPresenceListener(new PresenceListener() {
@Override
public void handle(PresenceEvent e) {
AbstractPresence presence = e.getPresence();
if (e.isIncoming()) {
boolean hasReachability = checkStanzaForReachabilityAndNotify(presence);
Jid contact = presence.getFrom().asBareJid();
if (!hasReachability && reachabilities.remove(contact) != null) {
// If no reachability was found in presence, check, if the contact has previously sent any reachability via presence.
notifyReachabilityListeners(contact, new ArrayList<Address>());
}
} else {
if (presence.isAvailable() && presence.getTo() == null) {
synchronized (addresses) {
if (!addresses.isEmpty()) {
presence.getExtensions().add(new Reachability(new ArrayList<>(addresses)));
}
}
}
}
}