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 ...@@ -290,23 +290,40 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
return; return;
} }
if (localServer.isLocal(update.getFrom())) { if (localServer.isLocal(update.getFrom())) {
boolean keepTrack = false;
WeakHashMap<ChannelHandler, Set<String>> map; WeakHashMap<ChannelHandler, Set<String>> map;
String name = update.getFrom().getNode(); String name = update.getFrom().getNode();
try {
if (name != null && !"".equals(name)) { if (name != null && !"".equals(name)) {
name = name.toLowerCase(); name = name.toLowerCase();
try {
Roster roster = rosterManager.getRoster(name); Roster roster = rosterManager.getRoster(name);
// If the directed presence was sent to an entity that is not in the user's // 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 // 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 // be able to send the unavailable presence to the entity
if (!roster.isRosterItem(update.getTo())) { 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()); map = directedPresences.get(update.getFrom().toString());
if (map == null) { if (map == null) {
// We are using a set to avoid duplicate jids in case the user // We are using a set to avoid duplicate jids in case the user
// sends several directed presences to the same handler. The Map also // sends several directed presences to the same handler. The Map also
// ensures that if the user sends several presences to the same handler // ensures that if the user sends several presences to the same handler
// we will have only one entry in the Map // 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>()); map.put(handler, new HashSet<String>());
directedPresences.put(update.getFrom().toString(), map); directedPresences.put(update.getFrom().toString(), map);
} }
...@@ -341,14 +358,6 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -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 * 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