diff --git a/changelog.html b/changelog.html
index d5d353c93..480caf2b8 100644
--- a/changelog.html
+++ b/changelog.html
@@ -47,6 +47,7 @@
1.9.0 (tbd)
- [#141] - Remove boilerplate code for managing MUC room affiliations
+ - [#136] - Implement group role handling when creating/updating a room
- [#130] - Add endpoint to create a new MUC service
- [#129] - Add endpoint(s) to invite users to a chatroom
- [#128] - Modify endpoints to add 'send invitations to affiliated users' as optional functionality
diff --git a/src/java/org/jivesoftware/openfire/plugin/rest/controller/MUCRoomController.java b/src/java/org/jivesoftware/openfire/plugin/rest/controller/MUCRoomController.java
index d826b4609..149f8f0b3 100644
--- a/src/java/org/jivesoftware/openfire/plugin/rest/controller/MUCRoomController.java
+++ b/src/java/org/jivesoftware/openfire/plugin/rest/controller/MUCRoomController.java
@@ -20,6 +20,7 @@
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.group.ConcurrentGroupList;
import org.jivesoftware.openfire.group.Group;
+import org.jivesoftware.openfire.group.GroupJID;
import org.jivesoftware.openfire.muc.*;
import org.jivesoftware.openfire.muc.spi.MUCRoomSearchInfo;
import org.jivesoftware.openfire.plugin.rest.RESTServicePlugin;
@@ -400,19 +401,40 @@ private boolean equalToAffiliations(MUCRoom room, MUCRoomEntity mucRoomEntity) {
if (mucRoomEntity == null || room == null) {
return false;
}
- Set admins = mucRoomEntity.getAdmins() != null ? new HashSet<>(mucRoomEntity.getAdmins()) : new HashSet<>();
- Set owners = mucRoomEntity.getOwners() != null ? new HashSet<>(mucRoomEntity.getOwners()) : new HashSet<>();
- Set members = mucRoomEntity.getMembers() != null ? new HashSet<>(mucRoomEntity.getMembers()) : new HashSet<>();
- Set outcasts = mucRoomEntity.getOutcasts() != null ? new HashSet<>(mucRoomEntity.getOutcasts()) : new HashSet<>();
-
- Set roomAdmins = room.getAdmins() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getAdmins())) : new HashSet<>();
- Set roomOwners = room.getOwners() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getOwners())) : new HashSet<>();
- Set roomMembers = room.getMembers() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getMembers())) : new HashSet<>();
- Set roomOutcasts = room.getOutcasts() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getOutcasts())) : new HashSet<>();
- return admins.equals(roomAdmins)
- && owners.equals(roomOwners)
- && members.equals(roomMembers)
- && outcasts.equals(roomOutcasts);
+
+ ConcurrentGroupList owners = new ConcurrentGroupList<>(room.getOwners());
+ ConcurrentGroupList admins = new ConcurrentGroupList<>(room.getAdmins());
+ ConcurrentGroupList members = new ConcurrentGroupList<>(room.getMembers());
+ ConcurrentGroupList outcasts = new ConcurrentGroupList<>(room.getOutcasts());
+
+ Set roomOwners = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(owners)); // convertJIDsToStringList ignores group JIDs.
+ Set roomAdmins = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(admins));
+ Set roomMembers = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(members));
+ Set roomOutcasts = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(outcasts));
+
+ Set entityOwners = mucRoomEntity.getOwners() != null ? new HashSet<>(mucRoomEntity.getOwners()) : new HashSet<>();
+ Set entityAdmins = mucRoomEntity.getAdmins() != null ? new HashSet<>(mucRoomEntity.getAdmins()) : new HashSet<>();
+ Set entityMembers = mucRoomEntity.getMembers() != null ? new HashSet<>(mucRoomEntity.getMembers()) : new HashSet<>();
+ Set entityOutcasts = mucRoomEntity.getOutcasts() != null ? new HashSet<>(mucRoomEntity.getOutcasts()) : new HashSet<>();
+
+ Set roomOwnerGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(owners.getGroups()));
+ Set roomAdminGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(admins.getGroups()));
+ Set roomMemberGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(members.getGroups()));
+ Set roomOutcastGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(outcasts.getGroups()));
+
+ Set entityOwnerGroups = mucRoomEntity.getOwnerGroups() != null ? new HashSet<>(mucRoomEntity.getOwnerGroups()) : new HashSet<>();
+ Set entityAdminGroups = mucRoomEntity.getAdminGroups() != null ? new HashSet<>(mucRoomEntity.getAdminGroups()) : new HashSet<>();
+ Set entityMemberGroups = mucRoomEntity.getMemberGroups() != null ? new HashSet<>(mucRoomEntity.getMemberGroups()) : new HashSet<>();
+ Set entityOutcastGroups = mucRoomEntity.getOutcastGroups() != null ? new HashSet<>(mucRoomEntity.getOutcastGroups()) : new HashSet<>();
+
+ return entityOwners.equals(roomOwners)
+ && entityAdmins.equals(roomAdmins)
+ && entityMembers.equals(roomMembers)
+ && entityOutcasts.equals(roomOutcasts)
+ && entityOwnerGroups.equals(roomOwnerGroups)
+ && entityAdminGroups.equals(roomAdminGroups)
+ && entityMemberGroups.equals(roomMemberGroups)
+ && entityOutcastGroups.equals(roomOutcastGroups);
}
/**
@@ -840,6 +862,13 @@ private Collection setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
List ownersToAdd = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners());
allNewAffiliations.addAll(ownersToAdd);
room.addOwners(ownersToAdd, room.getRole());
+ if (mucRoomEntity.getOwnerGroups() != null) {
+ for (final String groupName : mucRoomEntity.getOwnerGroups()) {
+ final JID groupJID = UserUtils.checkAndGetJID(groupName);
+ room.addOwner(groupJID, room.getRole());
+ allNewAffiliations.add(groupJID);
+ }
+ }
// Admins
if (mucRoomEntity.getAdmins() != null) {
@@ -848,6 +877,13 @@ private Collection setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
allNewAffiliations.addAll(newAdmins);
room.addAdmins(newAdmins, room.getRole());
}
+ if (mucRoomEntity.getAdminGroups() != null) {
+ for (final String groupName : mucRoomEntity.getAdminGroups()) {
+ final JID groupJID = UserUtils.checkAndGetJID(groupName);
+ room.addAdmin(groupJID, room.getRole());
+ allNewAffiliations.add(groupJID);
+ }
+ }
// Members
if (mucRoomEntity.getMembers() != null) {
@@ -858,6 +894,13 @@ private Collection setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
room.addMember(memberJid, null, room.getRole());
}
}
+ if (mucRoomEntity.getMemberGroups() != null) {
+ for (final String groupName : mucRoomEntity.getMemberGroups()) {
+ final JID groupJID = UserUtils.checkAndGetJID(groupName);
+ room.addMember(groupJID, null, room.getRole());
+ allNewAffiliations.add(groupJID);
+ }
+ }
// Outcasts
if (mucRoomEntity.getOutcasts() != null) {
@@ -865,7 +908,12 @@ private Collection setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
room.addOutcast(new JID(outcastJid), null, room.getRole());
}
}
-
+ if (mucRoomEntity.getOutcastGroups() != null) {
+ for (final String groupName : mucRoomEntity.getOutcastGroups()) {
+ final JID groupJID = UserUtils.checkAndGetJID(groupName);
+ room.addOutcast(groupJID, null, room.getRole());
+ }
+ }
return allNewAffiliations;
}