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

Fixed "Changes to group members are not pushed out dynamically". JM-109


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@828 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9f52f41c
...@@ -217,12 +217,13 @@ public class Group implements Cacheable { ...@@ -217,12 +217,13 @@ public class Group implements Cacheable {
if (current == null) { if (current == null) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
iter.remove();
String user = (String)current; String user = (String)current;
// Remove the group user from the backend store
provider.deleteMember(name, user);
// Update the group users' roster // Update the group users' roster
XMPPServer.getInstance().getRosterManager().groupUserDeleted(Group.this, user); XMPPServer.getInstance().getRosterManager().groupUserDeleted(Group.this, user);
// Remove the user from the collection in memory
iter.remove();
// Remove the group user from the backend store
provider.deleteMember(name, user);
} }
}; };
} }
......
...@@ -65,6 +65,7 @@ public class Roster implements Cacheable { ...@@ -65,6 +65,7 @@ public class Roster implements Cacheable {
* @param username The username of the user that owns this roster * @param username The username of the user that owns this roster
*/ */
public Roster(String username) { public Roster(String username) {
presenceManager = XMPPServer.getInstance().getPresenceManager();
sessionManager = SessionManager.getInstance(); sessionManager = SessionManager.getInstance();
this.username = username; this.username = username;
...@@ -271,11 +272,7 @@ public class Roster implements Cacheable { ...@@ -271,11 +272,7 @@ public class Roster implements Cacheable {
&& item.getAskStatus() == RosterItem.ASK_NONE)) { && item.getAskStatus() == RosterItem.ASK_NONE)) {
broadcast(item); broadcast(item);
} }
if (item.getSubStatus() == RosterItem.SUB_BOTH if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) {
|| item.getSubStatus() == RosterItem.SUB_TO) {
if (presenceManager == null) {
presenceManager = XMPPServer.getInstance().getPresenceManager();
}
presenceManager.probePresence(username, item.getJid()); presenceManager.probePresence(username, item.getJid());
} }
} }
...@@ -408,8 +405,7 @@ public class Roster implements Cacheable { ...@@ -408,8 +405,7 @@ public class Roster implements Cacheable {
for (String groupUser : users) { for (String groupUser : users) {
// Add the user to the answer if the user doesn't belong to the personal roster // Add the user to the answer if the user doesn't belong to the personal roster
// (since we have already added the user to the answer) // (since we have already added the user to the answer)
JID jid = new JID(groupUser, XMPPServer.getInstance().getServerInfo().getName(), JID jid = XMPPServer.getInstance().createJID(groupUser, null);
null);
if (!isRosterItem(jid) && !getUsername().equals(groupUser)) { if (!isRosterItem(jid) && !getUsername().equals(groupUser)) {
List<String> groups = sharedGroupUsers.get(jid); List<String> groups = sharedGroupUsers.get(jid);
if (groups == null) { if (groups == null) {
...@@ -476,26 +472,21 @@ public class Roster implements Cacheable { ...@@ -476,26 +472,21 @@ public class Roster implements Cacheable {
* @param addedUser the contact to update in the roster. * @param addedUser the contact to update in the roster.
*/ */
void addSharedUser(String sharedGroup, String addedUser) { void addSharedUser(String sharedGroup, String addedUser) {
JID jid = new JID(addedUser, XMPPServer.getInstance().getServerInfo().getName(), ""); RosterItem item = null;
JID jid = XMPPServer.getInstance().createJID(addedUser, "");
try { try {
// Get the RosterItem for the *local* user to add // Get the RosterItem for the *local* user to add
RosterItem item = getRosterItem(jid); item = getRosterItem(jid);
// Add the shared group to the list of shared groups
item.addSharedGroup(sharedGroup);
// Brodcast to all the user resources of the updated roster item
broadcast(item);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
try { try {
// Create a new RosterItem for this new user // Create a new RosterItem for this new user
User user = UserManager.getInstance().getUser(addedUser); User user = UserManager.getInstance().getUser(addedUser);
RosterItem item = new RosterItem(jid, RosterItem.SUB_BOTH, RosterItem.ASK_NONE, item =
RosterItem.RECV_NONE, user.getName(), null); new RosterItem(jid, RosterItem.SUB_BOTH, RosterItem.ASK_NONE,
item.addSharedGroup(sharedGroup); RosterItem.RECV_NONE, user.getName(), null);
// Add the new item to the list of items // Add the new item to the list of items
rosterItems.put(item.getJid().toBareJID(), item); rosterItems.put(item.getJid().toBareJID(), item);
// Brodcast to all the user resources of the updated roster item
broadcast(item);
} }
catch (UserNotFoundException ex) { catch (UserNotFoundException ex) {
Log.error("Group (" + sharedGroup + ") includes non-existent username (" + Log.error("Group (" + sharedGroup + ") includes non-existent username (" +
...@@ -503,6 +494,12 @@ public class Roster implements Cacheable { ...@@ -503,6 +494,12 @@ public class Roster implements Cacheable {
")"); ")");
} }
} }
// Add the shared group to the list of shared groups
item.addSharedGroup(sharedGroup);
// Brodcast to all the user resources of the updated roster item
broadcast(item);
// Presences of shared users are of type BOTH so probe for presences
presenceManager.probePresence(username, item.getJid());
} }
/** /**
...@@ -516,7 +513,7 @@ public class Roster implements Cacheable { ...@@ -516,7 +513,7 @@ public class Roster implements Cacheable {
* @param deletedUser the contact to update in the roster. * @param deletedUser the contact to update in the roster.
*/ */
void deleteSharedUser(String sharedGroup, String deletedUser) { void deleteSharedUser(String sharedGroup, String deletedUser) {
JID jid = new JID(deletedUser, XMPPServer.getInstance().getServerInfo().getName(), ""); JID jid = XMPPServer.getInstance().createJID(deletedUser, "");
try { try {
// Get the RosterItem for the *local* user to remove // Get the RosterItem for the *local* user to remove
RosterItem item = getRosterItem(jid); RosterItem item = getRosterItem(jid);
......
...@@ -146,6 +146,9 @@ public class RosterManager extends BasicModule { ...@@ -146,6 +146,9 @@ public class RosterManager extends BasicModule {
// Get all the group users // Get all the group users
Collection<String> users = new ArrayList<String>(group.getMembers()); Collection<String> users = new ArrayList<String>(group.getMembers());
users.addAll(group.getAdmins()); users.addAll(group.getAdmins());
// Get the roster of the added user.
Roster addedUserRoster = (Roster) CacheManager.getCache("username2roster").get(addedUser);
// Iterate on all the group users and update their rosters // Iterate on all the group users and update their rosters
for (String userToUpdate : users) { for (String userToUpdate : users) {
if (!addedUser.equals(userToUpdate)) { if (!addedUser.equals(userToUpdate)) {
...@@ -155,6 +158,10 @@ public class RosterManager extends BasicModule { ...@@ -155,6 +158,10 @@ public class RosterManager extends BasicModule {
if (roster != null) { if (roster != null) {
roster.addSharedUser(group.getName(), addedUser); roster.addSharedUser(group.getName(), addedUser);
} }
// Update the roster of the newly added group user
if (addedUserRoster != null) {
addedUserRoster.addSharedUser(group.getName(), userToUpdate);
}
} }
} }
} }
...@@ -169,6 +176,9 @@ public class RosterManager extends BasicModule { ...@@ -169,6 +176,9 @@ public class RosterManager extends BasicModule {
// Get all the group users // Get all the group users
Collection<String> users = new ArrayList<String>(group.getMembers()); Collection<String> users = new ArrayList<String>(group.getMembers());
users.addAll(group.getAdmins()); users.addAll(group.getAdmins());
// Get the roster of the deleted user.
Roster deletedUserRoster = (Roster) CacheManager.getCache("username2roster").get(deletedUser);
// Iterate on all the group users and update their rosters // Iterate on all the group users and update their rosters
for (String userToUpdate : users) { for (String userToUpdate : users) {
if (!deletedUser.equals(userToUpdate)) { if (!deletedUser.equals(userToUpdate)) {
...@@ -178,6 +188,10 @@ public class RosterManager extends BasicModule { ...@@ -178,6 +188,10 @@ public class RosterManager extends BasicModule {
if (roster != null) { if (roster != null) {
roster.deleteSharedUser(group.getName(), deletedUser); roster.deleteSharedUser(group.getName(), deletedUser);
} }
// Update the roster of the newly deleted group user
if (deletedUserRoster != null) {
deletedUserRoster.deleteSharedUser(group.getName(), userToUpdate);
}
} }
} }
} }
......
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