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

Fixed presences between different resources of the same user. JM-140


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@916 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3ce290cb
...@@ -360,6 +360,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen ...@@ -360,6 +360,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
routingTable.addRoute(node, defaultSession); routingTable.addRoute(node, defaultSession);
// Add route to the new session // Add route to the new session
routingTable.addRoute(session.getAddress(), session); routingTable.addRoute(session.getAddress(), session);
// Broadcast presence between the user's resources
broadcastPresenceToOtherResource(session);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
// Do nothing since the session is anonymous (? - shouldn't happen) // Do nothing since the session is anonymous (? - shouldn't happen)
...@@ -370,6 +372,37 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen ...@@ -370,6 +372,37 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
} }
} }
/**
* Broadcast initial presence from the user's new available resource to any of the user's
* existing available resources (if any).
*
* @param session the session that received the new presence and therefore will not receive
* the notification.
*/
private void broadcastPresenceToOtherResource(Session session) throws UserNotFoundException,
UnauthorizedException {
Presence presence = null;
SessionMap sessionMap = sessions.get(session.getUsername());
if (sessionMap != null) {
for (Session userSession : sessionMap.getAvailableSessions()) {
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.getConnection().deliver(presence);
}
// Send the presence of the session whose presence has changed to this other
// user's session
presence = session.getPresence().createCopy();
presence.setTo(userSession.getAddress());
userSession.getConnection().deliver(presence);
}
}
}
}
/** /**
* Notification message sent when a client sent an unavailable presence for the session. Making * Notification message sent when a client sent an unavailable presence for the session. Making
* the session unavailable means that the session is not eligible for receiving messages from * the session unavailable means that the session is not eligible for receiving messages from
...@@ -407,6 +440,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen ...@@ -407,6 +440,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
// Remove the route for the session's BARE address // Remove the route for the session's BARE address
routingTable.removeRoute(new JID(session.getAddress().getNode(), routingTable.removeRoute(new JID(session.getAddress().getNode(),
session.getAddress().getDomain(), "")); session.getAddress().getDomain(), ""));
// Broadcast presence between the user's resources
broadcastPresenceToOtherResource(session);
} }
else { else {
// Update the route for the session's BARE address // Update the route for the session's BARE address
...@@ -414,6 +449,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen ...@@ -414,6 +449,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
routingTable.addRoute(new JID(defaultSession.getAddress().getNode(), routingTable.addRoute(new JID(defaultSession.getAddress().getNode(),
defaultSession.getAddress().getDomain(), ""), defaultSession.getAddress().getDomain(), ""),
defaultSession); defaultSession);
// Broadcast presence between the user's resources
broadcastPresenceToOtherResource(session);
} }
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
......
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