1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-12 19:02:06 +01:00

Adding handling of error presence packets (SMACK-260).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10907 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2008-11-19 20:54:05 +00:00 committed by matt
parent b0614707bd
commit b499581c7e
2 changed files with 32 additions and 4 deletions

View file

@ -668,8 +668,9 @@ public class Roster {
userPresences.put(StringUtils.parseResource(from), presence);
// If the user is in the roster, fire an event.
RosterEntry entry = entries.get(key);
if (entry != null)
if (entry != null) {
fireRosterPresenceEvent(presence);
}
}
// If an "unavailable" packet.
else if (presence.getType() == Presence.Type.unavailable) {
@ -696,8 +697,9 @@ public class Roster {
}
// If the user is in the roster, fire an event.
RosterEntry entry = entries.get(key);
if (entry != null)
if (entry != null) {
fireRosterPresenceEvent(presence);
}
}
else if (presence.getType() == Presence.Type.subscribe) {
if (subscriptionMode == SubscriptionMode.accept_all) {
@ -725,6 +727,29 @@ public class Roster {
}
// Otherwise, in manual mode so ignore.
}
// Error presence packets from a bare JID mean we invalidate all existing
// presence info for the user.
else if (presence.getType() == Presence.Type.error &&
"".equals(StringUtils.parseResource(from)))
{
Map<String, Presence> userPresences;
if (!presenceMap.containsKey(key)) {
userPresences = new ConcurrentHashMap<String, Presence>();
presenceMap.put(key, userPresences);
}
else {
userPresences = presenceMap.get(key);
// Any other presence data is invalidated by the error packet.
userPresences.clear();
}
// Set the new presence using the empty resource as a key.
userPresences.put("", presence);
// If the user is in the roster, fire an event.
RosterEntry entry = entries.get(key);
if (entry != null) {
fireRosterPresenceEvent(presence);
}
}
}
}

View file

@ -92,7 +92,10 @@ public class Presence extends Packet {
* Returns true if the {@link Type presence type} is available (online) and
* false if the user is unavailable (offline), or if this is a presence packet
* involved in a subscription operation. This is a convenience method
* equivalent to <tt>getType() == Presence.Type.available</tt>.
* equivalent to <tt>getType() == Presence.Type.available</tt>. Note that even
* when the user is available, their presence mode may be {@link Mode#away away},
* {@link Mode#xa extended away} or {@link Mode#dnd do not disturb}. Use
* {@link #isAway()} to determine if the user is away.
*
* @return true if the presence type is available.
*/