Commit 12ec829b authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Removed coupling between groups and roster. JM-109


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@838 b35dd754-fafc-0310-a699-88a17e54d16e
parent be689693
...@@ -17,9 +17,7 @@ import org.jivesoftware.util.ClassUtils; ...@@ -17,9 +17,7 @@ import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.user.User; import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.JiveGlobals; import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.messenger.XMPPServer;
import org.jivesoftware.messenger.event.GroupEventDispatcher; import org.jivesoftware.messenger.event.GroupEventDispatcher;
import org.jivesoftware.messenger.roster.RosterManager;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -130,10 +128,6 @@ public class GroupManager { ...@@ -130,10 +128,6 @@ public class GroupManager {
// Expire all relevant caches. // Expire all relevant caches.
groupCache.remove(group.getName()); groupCache.remove(group.getName());
// Notify the RosterManager that the group has been deleted
RosterManager rosterManager = XMPPServer.getInstance().getRosterManager();
rosterManager.groupDeleted(group);
} }
/** /**
......
...@@ -17,11 +17,14 @@ import org.jivesoftware.util.CacheManager; ...@@ -17,11 +17,14 @@ import org.jivesoftware.util.CacheManager;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.user.UserNotFoundException; import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.messenger.SharedGroupException; import org.jivesoftware.messenger.SharedGroupException;
import org.jivesoftware.messenger.event.GroupEventListener;
import org.jivesoftware.messenger.event.GroupEventDispatcher;
import org.jivesoftware.messenger.group.Group; import org.jivesoftware.messenger.group.Group;
import java.util.Iterator; import java.util.Iterator;
import java.util.Collection; import java.util.Collection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
/** /**
* A simple service that allows components to retrieve a roster based solely on the ID * A simple service that allows components to retrieve a roster based solely on the ID
...@@ -34,12 +37,14 @@ import java.util.ArrayList; ...@@ -34,12 +37,14 @@ import java.util.ArrayList;
* *
* @author Iain Shigeoka * @author Iain Shigeoka
*/ */
public class RosterManager extends BasicModule { public class RosterManager extends BasicModule implements GroupEventListener {
private Cache rosterCache = null; private Cache rosterCache = null;
public RosterManager() { public RosterManager() {
super("Roster Manager"); super("Roster Manager");
// Add the new instance as a listener of group events
GroupEventDispatcher.addListener(this);
} }
/** /**
...@@ -121,12 +126,11 @@ public class RosterManager extends BasicModule { ...@@ -121,12 +126,11 @@ public class RosterManager extends BasicModule {
} }
} }
/** public void groupCreated(Group group, Map params) {
* Notification that a Group has been deleted. Update the group users' roster accordingly. //Do nothing
* }
* @param group the group that has been deleted.
*/ public void groupDeleting(Group group, Map params) {
public void groupDeleted(Group group) {
// 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());
...@@ -136,13 +140,37 @@ public class RosterManager extends BasicModule { ...@@ -136,13 +140,37 @@ public class RosterManager extends BasicModule {
} }
} }
public void groupModified(Group group, Map params) {
//TODO Implement this
}
public void memberAdded(Group group, Map params) {
String addedUser = (String) params.get("member");
groupUserAdded(group, addedUser);
}
public void memberRemoved(Group group, Map params) {
String addedUser = (String) params.get("member");
groupUserDeleted(group, addedUser);
}
public void adminAdded(Group group, Map params) {
String addedUser = (String) params.get("admin");
groupUserAdded(group, addedUser);
}
public void adminRemoved(Group group, Map params) {
String addedUser = (String) params.get("admin");
groupUserDeleted(group, addedUser);
}
/** /**
* Notification that a Group user has been added. Update the group users' roster accordingly. * Notification that a Group user has been added. Update the group users' roster accordingly.
* *
* @param group the group where the user was added. * @param group the group where the user was added.
* @param addedUser the username of the user that has been added to the group. * @param addedUser the username of the user that has been added to the group.
*/ */
public void groupUserAdded(Group group, String addedUser) { private void groupUserAdded(Group group, String addedUser) {
// 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());
...@@ -172,7 +200,7 @@ public class RosterManager extends BasicModule { ...@@ -172,7 +200,7 @@ public class RosterManager extends BasicModule {
* @param group the group from where the user was deleted. * @param group the group from where the user was deleted.
* @param deletedUser the username of the user that has been deleted from the group. * @param deletedUser the username of the user that has been deleted from the group.
*/ */
public void groupUserDeleted(Group group, String deletedUser) { private void groupUserDeleted(Group group, String deletedUser) {
// 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());
...@@ -181,19 +209,16 @@ public class RosterManager extends BasicModule { ...@@ -181,19 +209,16 @@ public class RosterManager extends BasicModule {
// 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)) { // Get the roster to update
// Get the roster to update Roster roster = (Roster)CacheManager.getCache("username2roster").get(userToUpdate);
Roster roster = (Roster)CacheManager.getCache("username2roster").get(userToUpdate); // Only update rosters in memory
// Only update rosters in memory 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
// Update the roster of the newly deleted group user if (deletedUserRoster != null) {
if (deletedUserRoster != null) { deletedUserRoster.deleteSharedUser(group.getName(), userToUpdate);
deletedUserRoster.deleteSharedUser(group.getName(), userToUpdate);
}
} }
} }
} }
} }
\ No newline at end of file
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