Remove "otherJid" when receiving unavailable presence.

This commit is contained in:
chteufleur 2018-10-05 19:34:16 +02:00
parent ebe4208502
commit 27f506c253
1 changed files with 20 additions and 14 deletions

View File

@ -172,22 +172,28 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
} }
@Override @Override
public void presenceAvailable(FullJid address, Presence availablePresence) { public void presenceAvailable(FullJid address, Presence presence) {
String fullJid = address.asFullJidIfPossible().toString(); String fullJid = address.asFullJidIfPossible().toString();
if (!fullJid.equals(jid) && (otherJid == null || !fullJid.equals(otherJid))) { if (presence.getType() == Presence.Type.available) {
Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM "+fullJid); if (!fullJid.equals(jid) && (otherJid == null || !fullJid.equals(otherJid))) {
otherJid = fullJid; Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM " + fullJid);
try { otherJid = fullJid;
sendPresenceAvailable(fullJid); try {
} catch (SmackException.NotConnectedException e) { sendPresenceAvailable(fullJid);
e.printStackTrace(); } catch (SmackException.NotConnectedException e) {
} catch (InterruptedException e) { e.printStackTrace();
e.printStackTrace(); } catch (InterruptedException e) {
} catch (XmppStringprepException e) { e.printStackTrace();
e.printStackTrace(); } catch (XmppStringprepException e) {
e.printStackTrace();
}
setChanged();
notifyObservers(new Notification(NOTIF_NEW_PRESENCE_RECEIVED).addExtra(NOTIF_NEW_PRESENCE_RECEIVED_VALUE_JID, otherJid));
}
} else if (presence.getType() == Presence.Type.unavailable) {
if (otherJid != null && otherJid.equals(fullJid)) {
otherJid = null;
} }
setChanged();
notifyObservers(new Notification(NOTIF_NEW_PRESENCE_RECEIVED).addExtra(NOTIF_NEW_PRESENCE_RECEIVED_VALUE_JID, otherJid));
} }
} }