Commit 57c61c98 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Fixed all known (and some not reported) issues with shared groups. JM-148


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@997 b35dd754-fafc-0310-a699-88a17e54d16e
parent 18f66146
...@@ -16,6 +16,7 @@ import org.jivesoftware.util.Cacheable; ...@@ -16,6 +16,7 @@ import org.jivesoftware.util.Cacheable;
import org.jivesoftware.util.CacheSizes; import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.messenger.group.GroupManager; import org.jivesoftware.messenger.group.GroupManager;
import org.jivesoftware.messenger.group.GroupNotFoundException; import org.jivesoftware.messenger.group.GroupNotFoundException;
import org.jivesoftware.messenger.group.Group;
import org.jivesoftware.messenger.SharedGroupException; import org.jivesoftware.messenger.SharedGroupException;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -124,8 +125,8 @@ public class RosterItem implements Cacheable { ...@@ -124,8 +125,8 @@ public class RosterItem implements Cacheable {
protected JID jid; protected JID jid;
protected String nickname; protected String nickname;
protected List<String> groups; protected List<String> groups;
protected Set<String> sharedGroups = new HashSet<String>(); protected Set<Group> sharedGroups = new HashSet<Group>();
protected Set<String> invisibleSharedGroups = new HashSet<String>(); protected Set<Group> invisibleSharedGroups = new HashSet<Group>();
protected SubType subStatus; protected SubType subStatus;
protected AskType askStatus; protected AskType askStatus;
private long rosterID; private long rosterID;
...@@ -311,7 +312,9 @@ public class RosterItem implements Cacheable { ...@@ -311,7 +312,9 @@ public class RosterItem implements Cacheable {
} }
else { else {
// Raise an error if the user is trying to remove the item from a shared group // Raise an error if the user is trying to remove the item from a shared group
for (String groupName : getSharedGroups()) { for (Group group: getSharedGroups()) {
// Get the display name of the group
String groupName = group.getProperties().get("sharedRoster.displayName");
// Check if the group has been removed from the new groups list // Check if the group has been removed from the new groups list
if (!groups.contains(groupName)) { if (!groups.contains(groupName)) {
throw new SharedGroupException("Cannot remove item from shared group"); throw new SharedGroupException("Cannot remove item from shared group");
...@@ -340,7 +343,7 @@ public class RosterItem implements Cacheable { ...@@ -340,7 +343,7 @@ public class RosterItem implements Cacheable {
* *
* @return The shared groups this item belongs to. * @return The shared groups this item belongs to.
*/ */
public Collection<String> getSharedGroups() { public Collection<Group> getSharedGroups() {
return sharedGroups; return sharedGroups;
} }
...@@ -351,7 +354,7 @@ public class RosterItem implements Cacheable { ...@@ -351,7 +354,7 @@ public class RosterItem implements Cacheable {
* *
* @return The shared groups this item belongs to. * @return The shared groups this item belongs to.
*/ */
public Collection<String> getInvisibleSharedGroups() { public Collection<Group> getInvisibleSharedGroups() {
return invisibleSharedGroups; return invisibleSharedGroups;
} }
...@@ -360,7 +363,7 @@ public class RosterItem implements Cacheable { ...@@ -360,7 +363,7 @@ public class RosterItem implements Cacheable {
* *
* @param sharedGroup The shared group to add to the list of shared groups. * @param sharedGroup The shared group to add to the list of shared groups.
*/ */
public void addSharedGroup(String sharedGroup) { public void addSharedGroup(Group sharedGroup) {
sharedGroups.add(sharedGroup); sharedGroups.add(sharedGroup);
invisibleSharedGroups.remove(sharedGroup); invisibleSharedGroups.remove(sharedGroup);
} }
...@@ -372,7 +375,7 @@ public class RosterItem implements Cacheable { ...@@ -372,7 +375,7 @@ public class RosterItem implements Cacheable {
* *
* @param sharedGroup The shared group to add to the list of shared groups. * @param sharedGroup The shared group to add to the list of shared groups.
*/ */
public void addInvisibleSharedGroup(String sharedGroup) { public void addInvisibleSharedGroup(Group sharedGroup) {
invisibleSharedGroups.add(sharedGroup); invisibleSharedGroups.add(sharedGroup);
} }
...@@ -381,7 +384,7 @@ public class RosterItem implements Cacheable { ...@@ -381,7 +384,7 @@ public class RosterItem implements Cacheable {
* *
* @param sharedGroup The shared group to remove from the list of shared groups. * @param sharedGroup The shared group to remove from the list of shared groups.
*/ */
public void removeSharedGroup(String sharedGroup) { public void removeSharedGroup(Group sharedGroup) {
sharedGroups.remove(sharedGroup); sharedGroups.remove(sharedGroup);
invisibleSharedGroups.remove(sharedGroup); invisibleSharedGroups.remove(sharedGroup);
} }
......
...@@ -283,7 +283,7 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -283,7 +283,7 @@ public class RosterManager extends BasicModule implements GroupEventListener {
Roster roster = (Roster) CacheManager.getCache("username2roster").get(updatedUser); Roster roster = (Roster) CacheManager.getCache("username2roster").get(updatedUser);
if (roster != null) { if (roster != null) {
// Update the roster with the new group display name // Update the roster with the new group display name
roster.shareGroupRenamed(originalValue, currentValue, users); roster.shareGroupRenamed(users);
} }
} }
} }
...@@ -407,8 +407,6 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -407,8 +407,6 @@ public class RosterManager extends BasicModule implements GroupEventListener {
private void groupUserDeleted(Group group, Collection<String> users, String deletedUser) { private void groupUserDeleted(Group group, Collection<String> users, String deletedUser) {
// Get the roster of the deleted user. // Get the roster of the deleted user.
Roster deletedUserRoster = (Roster) CacheManager.getCache("username2roster").get(deletedUser); Roster deletedUserRoster = (Roster) CacheManager.getCache("username2roster").get(deletedUser);
// Get the display name of the group
String groupName = group.getProperties().get("sharedRoster.displayName");
// Iterate on all the affected users and update their rosters // Iterate on all the affected users and update their rosters
for (String userToUpdate : users) { for (String userToUpdate : users) {
...@@ -416,7 +414,7 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -416,7 +414,7 @@ public class RosterManager extends BasicModule implements GroupEventListener {
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(groupName, deletedUser); roster.deleteSharedUser(group, 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) {
...@@ -523,8 +521,6 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -523,8 +521,6 @@ public class RosterManager extends BasicModule implements GroupEventListener {
// Get the roster of the user from which we need to remove the shared group users // Get the roster of the user from which we need to remove the shared group users
Roster userRoster = (Roster) CacheManager.getCache("username2roster").get(username); Roster userRoster = (Roster) CacheManager.getCache("username2roster").get(username);
// Get the display name of the group
String groupName = group.getProperties().get("sharedRoster.displayName");
// Iterate on all the group users and update their rosters // Iterate on all the group users and update their rosters
for (String userToRemove : users) { for (String userToRemove : users) {
...@@ -532,7 +528,7 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -532,7 +528,7 @@ public class RosterManager extends BasicModule implements GroupEventListener {
Roster roster = (Roster)CacheManager.getCache("username2roster").get(userToRemove); Roster roster = (Roster)CacheManager.getCache("username2roster").get(userToRemove);
// Only update rosters in memory // Only update rosters in memory
if (roster != null) { if (roster != null) {
roster.deleteSharedUser(groupName, username); roster.deleteSharedUser(group, username);
} }
// Update the roster of the user // Update the roster of the user
if (userRoster != null) { if (userRoster != null) {
...@@ -636,7 +632,8 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -636,7 +632,8 @@ public class RosterManager extends BasicModule implements GroupEventListener {
* Returns true if a group in the first collection may mutually see a group of the * Returns true if a group in the first collection may mutually see a group of the
* second collection. More precisely, return true if both collections contain a public * second collection. More precisely, return true if both collections contain a public
* group (i.e. anybody can see the group) or if both collection have a group that may see * group (i.e. anybody can see the group) or if both collection have a group that may see
* each other and the users are members of those groups. * each other and the users are members of those groups or if one group is public and the
* other group allowed the public group to see it.
* *
* @param user the name of the user associated to the first collection of groups. * @param user the name of the user associated to the first collection of groups.
* @param groups a collection of groups to check against the other collection of groups. * @param groups a collection of groups to check against the other collection of groups.
...@@ -673,6 +670,23 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -673,6 +670,23 @@ public class RosterManager extends BasicModule implements GroupEventListener {
} }
} }
} }
else if ("everybody".equals(showInRoster) && "onlyGroup".equals(otherShowInRoster)) {
// Return true if one group is public and the other group allowed the public
// group to see him
String otherGroupNames = otherGroup.getProperties().get("sharedRoster.groupList");
if (otherGroupNames != null && otherGroupNames.contains(group.getName())) {
return true;
}
}
else if ("onlyGroup".equals(showInRoster) && "everybody".equals(otherShowInRoster)) {
// Return true if one group is public and the other group allowed the public
// group to see him
String groupNames = group.getProperties().get("sharedRoster.groupList");
// Return true if each group may see the other group
if (groupNames != null && groupNames.contains(otherGroup.getName())) {
return true;
}
}
} }
} }
return false; return false;
......
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