Commit 077aaa1d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Presences are now correctly refreshed to all user resources. JM-702

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4093 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7041c144
......@@ -733,7 +733,7 @@ public class SessionManager extends BasicModule {
// Add route to the new session
routingTable.addRoute(session.getAddress(), session);
// Broadcast presence between the user's resources
broadcastPresenceToOtherResource(session);
broadcastPresenceOfOtherResource(session);
}
catch (UserNotFoundException e) {
// Do nothing since the session is anonymous (? - shouldn't happen)
......@@ -742,13 +742,11 @@ public class SessionManager extends BasicModule {
}
/**
* Broadcast initial presence from the user's new available resource to any of the user's
* existing available resources (if any).
* Sends the presences of other connected resources to the resource that just connected.
*
* @param session the session that received the new presence and therefore will not receive
* the notification.
* @param session the newly created session.
*/
private void broadcastPresenceToOtherResource(ClientSession session)
private void broadcastPresenceOfOtherResource(ClientSession session)
throws UserNotFoundException {
Presence presence;
Collection<ClientSession> availableSession;
......@@ -759,14 +757,29 @@ public class SessionManager extends BasicModule {
if (userSession != session) {
// Send the presence of an existing session to the session that has just changed
// the presence
if (session.getPresence().isAvailable()) {
presence = userSession.getPresence().createCopy();
presence.setTo(session.getAddress());
session.process(presence);
}
// Send the presence of the session whose presence has changed to this other
// user's session
presence = session.getPresence().createCopy();
presence = userSession.getPresence().createCopy();
presence.setTo(session.getAddress());
session.process(presence);
}
}
}
}
/**
* Broadcasts presence updates from the originating user's resource to any of the user's
* existing available resources (if any).
*
* @param originatingResource the full JID of the session that sent the presence update.
*/
public void broadcastPresenceToOtherResources(JID originatingResource, Presence presence) {
Collection<ClientSession> availableSession;
SessionMap sessionMap = sessions.get(originatingResource.getNode());
if (sessionMap != null) {
availableSession = new ArrayList<ClientSession>(sessionMap.getAvailableSessions());
for (ClientSession userSession : availableSession) {
if (userSession.getAddress() != originatingResource) {
// Send the presence of the session whose presence has changed to
// this other user's session
presence.setTo(userSession.getAddress());
userSession.process(presence);
}
......@@ -807,8 +820,6 @@ public class SessionManager extends BasicModule {
// Remove the route for the session's BARE address
routingTable.removeRoute(new JID(session.getAddress().getNode(),
session.getAddress().getDomain(), ""));
// Broadcast presence between the user's resources
broadcastPresenceToOtherResource(session);
}
else {
// Update the order of the sessions based on the new presence of this session
......@@ -818,8 +829,6 @@ public class SessionManager extends BasicModule {
routingTable.addRoute(new JID(defaultSession.getAddress().getNode(),
defaultSession.getAddress().getDomain(), ""),
defaultSession);
// Broadcast presence between the user's resources
broadcastPresenceToOtherResource(session);
}
}
catch (UserNotFoundException e) {
......
......@@ -520,10 +520,11 @@ public class Roster implements Cacheable {
}
// Get the privacy list of this user
PrivacyList list = null;
if (packet.getFrom() != null) {
JID from = packet.getFrom();
if (from != null) {
// Try to use the active list of the session. If none was found then try to use
// the default privacy list of the session
ClientSession session = sessionManager.getSession(packet.getFrom());
ClientSession session = sessionManager.getSession(from);
if (session != null) {
list = session.getActiveList();
list = list == null ? session.getDefaultList() : list;
......@@ -533,6 +534,7 @@ public class Roster implements Cacheable {
// No privacy list was found (based on the session) so check if there is a default list
list = PrivacyListManager.getInstance().getDefaultPrivacyList(username);
}
// Broadcast presence to subscribed entities
for (RosterItem item : rosterItems.values()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH
|| item.getSubStatus() == RosterItem.SUB_FROM) {
......@@ -555,6 +557,10 @@ public class Roster implements Cacheable {
}
}
}
if (from != null) {
// Broadcast presence to other user's resources
sessionManager.broadcastPresenceToOtherResources(from, packet);
}
}
/**
......
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