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
public void presenceAvailable(FullJid address, Presence availablePresence) {
public void presenceAvailable(FullJid address, Presence presence) {
String fullJid = address.asFullJidIfPossible().toString();
if (!fullJid.equals(jid) && (otherJid == null || !fullJid.equals(otherJid))) {
Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM "+fullJid);
otherJid = fullJid;
try {
sendPresenceAvailable(fullJid);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XmppStringprepException e) {
e.printStackTrace();
if (presence.getType() == Presence.Type.available) {
if (!fullJid.equals(jid) && (otherJid == null || !fullJid.equals(otherJid))) {
Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM " + fullJid);
otherJid = fullJid;
try {
sendPresenceAvailable(fullJid);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
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));
}
}