Commit dea2e15f authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added support for directed presences of anonymous users. JM-166


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@973 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9de7b243
......@@ -290,23 +290,40 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
return;
}
if (localServer.isLocal(update.getFrom())) {
boolean keepTrack = false;
WeakHashMap<ChannelHandler, Set<String>> map;
String name = update.getFrom().getNode();
try {
if (name != null && !"".equals(name)) {
name = name.toLowerCase();
try {
Roster roster = rosterManager.getRoster(name);
// If the directed presence was sent to an entity that is not in the user's
// roster, keep a registry of this so that when the user goes offline we will
// be able to send the unavailable presence to the entity
if (!roster.isRosterItem(update.getTo())) {
keepTrack = true;
}
}
catch (UserNotFoundException e) {
Log.warn("Presence being sent from unknown user " + name, e);
}
catch (PacketException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
else if (update.getFrom().getResource() != null){
// Keep always track of anonymous users directed presences
keepTrack = true;
}
if (keepTrack) {
map = directedPresences.get(update.getFrom().toString());
if (map == null) {
// We are using a set to avoid duplicate jids in case the user
// sends several directed presences to the same handler. The Map also
// ensures that if the user sends several presences to the same handler
// we will have only one entry in the Map
map = new WeakHashMap<ChannelHandler,Set<String>>();
map = new WeakHashMap<ChannelHandler, Set<String>>();
map.put(handler, new HashSet<String>());
directedPresences.put(update.getFrom().toString(), map);
}
......@@ -341,14 +358,6 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
}
}
}
catch (UserNotFoundException e) {
Log.warn("Presence being sent from unknown user " + name, e);
}
catch (PacketException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
/**
* Sends an unavailable presence to the entities that received a directed (available) presence
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment