mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 07:22:07 +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:
parent
c9bf420b37
commit
00f5008794
1 changed files with 19 additions and 3 deletions
|
@ -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,10 +533,15 @@ public class Roster {
|
|||
}
|
||||
}
|
||||
if (presence == null) {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue