1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-26 12:37:58 +01:00

Consider also unavailable presences when dealing with the roster

This is needed for checking <delay/> extensions in unavailable
presence stanzas.

Signed-off-by: Daniele Ricci <daniele.athome@gmail.com>
This commit is contained in:
Daniele Ricci 2014-11-27 18:09:18 +01:00 committed by Florian Schmaus
parent c9bf420b37
commit 00f5008794

View file

@ -502,10 +502,13 @@ public class Roster {
// Find the resource with the highest priority
// Might be changed to use the resource with the highest availability instead.
Presence presence = null;
// This is used in case no available presence is found
Presence unavailable = null;
for (String resource : userPresences.keySet()) {
Presence p = userPresences.get(resource);
if (!p.isAvailable()) {
unavailable = p;
continue;
}
// Chose presence with highest priority first.
@ -530,9 +533,14 @@ public class Roster {
}
}
if (presence == null) {
presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user);
return presence;
if (unavailable != null) {
return unavailable;
}
else {
presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user);
return presence;
}
}
else {
return presence;
@ -593,14 +601,22 @@ public class Roster {
}
else {
List<Presence> answer = new ArrayList<Presence>();
// Used in case no available presence is found
Presence unavailable = null;
for (Presence presence : userPresences.values()) {
if (presence.isAvailable()) {
answer.add(presence);
}
else {
unavailable = presence;
}
}
if (!answer.isEmpty()) {
res = answer;
}
else if (unavailable != null) {
res = Arrays.asList(unavailable);
}
else {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user);