1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-29 09:42:06 +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 // Find the resource with the highest priority
// Might be changed to use the resource with the highest availability instead. // Might be changed to use the resource with the highest availability instead.
Presence presence = null; Presence presence = null;
// This is used in case no available presence is found
Presence unavailable = null;
for (String resource : userPresences.keySet()) { for (String resource : userPresences.keySet()) {
Presence p = userPresences.get(resource); Presence p = userPresences.get(resource);
if (!p.isAvailable()) { if (!p.isAvailable()) {
unavailable = p;
continue; continue;
} }
// Chose presence with highest priority first. // Chose presence with highest priority first.
@ -530,10 +533,15 @@ public class Roster {
} }
} }
if (presence == null) { if (presence == null) {
if (unavailable != null) {
return unavailable;
}
else {
presence = new Presence(Presence.Type.unavailable); presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user); presence.setFrom(user);
return presence; return presence;
} }
}
else { else {
return presence; return presence;
} }
@ -593,14 +601,22 @@ public class Roster {
} }
else { else {
List<Presence> answer = new ArrayList<Presence>(); List<Presence> answer = new ArrayList<Presence>();
// Used in case no available presence is found
Presence unavailable = null;
for (Presence presence : userPresences.values()) { for (Presence presence : userPresences.values()) {
if (presence.isAvailable()) { if (presence.isAvailable()) {
answer.add(presence); answer.add(presence);
} }
else {
unavailable = presence;
}
} }
if (!answer.isEmpty()) { if (!answer.isEmpty()) {
res = answer; res = answer;
} }
else if (unavailable != null) {
res = Arrays.asList(unavailable);
}
else { else {
Presence presence = new Presence(Presence.Type.unavailable); Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user); presence.setFrom(user);