1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-23 06:42:05 +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); userPresences.put(StringUtils.parseResource(from), presence);
// If the user is in the roster, fire an event. // If the user is in the roster, fire an event.
RosterEntry entry = entries.get(key); RosterEntry entry = entries.get(key);
if (entry != null) if (entry != null) {
fireRosterPresenceEvent(presence); fireRosterPresenceEvent(presence);
}
} }
// If an "unavailable" packet. // If an "unavailable" packet.
else if (presence.getType() == Presence.Type.unavailable) { else if (presence.getType() == Presence.Type.unavailable) {
@ -696,8 +697,9 @@ public class Roster {
} }
// If the user is in the roster, fire an event. // If the user is in the roster, fire an event.
RosterEntry entry = entries.get(key); RosterEntry entry = entries.get(key);
if (entry != null) if (entry != null) {
fireRosterPresenceEvent(presence); fireRosterPresenceEvent(presence);
}
} }
else if (presence.getType() == Presence.Type.subscribe) { else if (presence.getType() == Presence.Type.subscribe) {
if (subscriptionMode == SubscriptionMode.accept_all) { if (subscriptionMode == SubscriptionMode.accept_all) {
@ -725,6 +727,29 @@ public class Roster {
} }
// Otherwise, in manual mode so ignore. // 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);
}
}
} }
} }
@ -852,4 +877,4 @@ public class Roster {
fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries); fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
} }
} }
} }

View file

@ -92,7 +92,10 @@ public class Presence extends Packet {
* Returns true if the {@link Type presence type} is available (online) and * 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 * false if the user is unavailable (offline), or if this is a presence packet
* involved in a subscription operation. This is a convenience method * 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. * @return true if the presence type is available.
*/ */