Skip to content

Commit e2fb14f

Browse files
guusdkFishbowler
authored andcommitted
fixes #136: Implement group role handling when creating/updating a room
Prior to this commit, affiliation-groups (memberGroups, adminGroups, ownerGroups and outcastGroups) that were present in MUC room entities used to create up update a MUC room, were ignored.
1 parent 13bac32 commit e2fb14f

2 files changed

Lines changed: 63 additions & 14 deletions

File tree

changelog.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ <h1>
4747
<p><b>1.9.0</b> (tbd)</p>
4848
<ul>
4949
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/141'>#141</a>] - Remove boilerplate code for managing MUC room affiliations</li>
50+
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/136'>#136</a>] - Implement group role handling when creating/updating a room</li>
5051
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/130'>#130</a>] - Add endpoint to create a new MUC service</li>
5152
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/129'>#129</a>] - Add endpoint(s) to invite users to a chatroom</li>
5253
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/128'>#128</a>] - Modify endpoints to add 'send invitations to affiliated users' as optional functionality</li>

src/java/org/jivesoftware/openfire/plugin/rest/controller/MUCRoomController.java

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.jivesoftware.openfire.XMPPServer;
2121
import org.jivesoftware.openfire.group.ConcurrentGroupList;
2222
import org.jivesoftware.openfire.group.Group;
23+
import org.jivesoftware.openfire.group.GroupJID;
2324
import org.jivesoftware.openfire.muc.*;
2425
import org.jivesoftware.openfire.muc.spi.MUCRoomSearchInfo;
2526
import org.jivesoftware.openfire.plugin.rest.RESTServicePlugin;
@@ -400,19 +401,40 @@ private boolean equalToAffiliations(MUCRoom room, MUCRoomEntity mucRoomEntity) {
400401
if (mucRoomEntity == null || room == null) {
401402
return false;
402403
}
403-
Set<String> admins = mucRoomEntity.getAdmins() != null ? new HashSet<>(mucRoomEntity.getAdmins()) : new HashSet<>();
404-
Set<String> owners = mucRoomEntity.getOwners() != null ? new HashSet<>(mucRoomEntity.getOwners()) : new HashSet<>();
405-
Set<String> members = mucRoomEntity.getMembers() != null ? new HashSet<>(mucRoomEntity.getMembers()) : new HashSet<>();
406-
Set<String> outcasts = mucRoomEntity.getOutcasts() != null ? new HashSet<>(mucRoomEntity.getOutcasts()) : new HashSet<>();
407-
408-
Set<String> roomAdmins = room.getAdmins() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getAdmins())) : new HashSet<>();
409-
Set<String> roomOwners = room.getOwners() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getOwners())) : new HashSet<>();
410-
Set<String> roomMembers = room.getMembers() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getMembers())) : new HashSet<>();
411-
Set<String> roomOutcasts = room.getOutcasts() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getOutcasts())) : new HashSet<>();
412-
return admins.equals(roomAdmins)
413-
&& owners.equals(roomOwners)
414-
&& members.equals(roomMembers)
415-
&& outcasts.equals(roomOutcasts);
404+
405+
ConcurrentGroupList<JID> owners = new ConcurrentGroupList<>(room.getOwners());
406+
ConcurrentGroupList<JID> admins = new ConcurrentGroupList<>(room.getAdmins());
407+
ConcurrentGroupList<JID> members = new ConcurrentGroupList<>(room.getMembers());
408+
ConcurrentGroupList<JID> outcasts = new ConcurrentGroupList<>(room.getOutcasts());
409+
410+
Set<String> roomOwners = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(owners)); // convertJIDsToStringList ignores group JIDs.
411+
Set<String> roomAdmins = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(admins));
412+
Set<String> roomMembers = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(members));
413+
Set<String> roomOutcasts = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(outcasts));
414+
415+
Set<String> entityOwners = mucRoomEntity.getOwners() != null ? new HashSet<>(mucRoomEntity.getOwners()) : new HashSet<>();
416+
Set<String> entityAdmins = mucRoomEntity.getAdmins() != null ? new HashSet<>(mucRoomEntity.getAdmins()) : new HashSet<>();
417+
Set<String> entityMembers = mucRoomEntity.getMembers() != null ? new HashSet<>(mucRoomEntity.getMembers()) : new HashSet<>();
418+
Set<String> entityOutcasts = mucRoomEntity.getOutcasts() != null ? new HashSet<>(mucRoomEntity.getOutcasts()) : new HashSet<>();
419+
420+
Set<String> roomOwnerGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(owners.getGroups()));
421+
Set<String> roomAdminGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(admins.getGroups()));
422+
Set<String> roomMemberGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(members.getGroups()));
423+
Set<String> roomOutcastGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(outcasts.getGroups()));
424+
425+
Set<String> entityOwnerGroups = mucRoomEntity.getOwnerGroups() != null ? new HashSet<>(mucRoomEntity.getOwnerGroups()) : new HashSet<>();
426+
Set<String> entityAdminGroups = mucRoomEntity.getAdminGroups() != null ? new HashSet<>(mucRoomEntity.getAdminGroups()) : new HashSet<>();
427+
Set<String> entityMemberGroups = mucRoomEntity.getMemberGroups() != null ? new HashSet<>(mucRoomEntity.getMemberGroups()) : new HashSet<>();
428+
Set<String> entityOutcastGroups = mucRoomEntity.getOutcastGroups() != null ? new HashSet<>(mucRoomEntity.getOutcastGroups()) : new HashSet<>();
429+
430+
return entityOwners.equals(roomOwners)
431+
&& entityAdmins.equals(roomAdmins)
432+
&& entityMembers.equals(roomMembers)
433+
&& entityOutcasts.equals(roomOutcasts)
434+
&& entityOwnerGroups.equals(roomOwnerGroups)
435+
&& entityAdminGroups.equals(roomAdminGroups)
436+
&& entityMemberGroups.equals(roomMemberGroups)
437+
&& entityOutcastGroups.equals(roomOutcastGroups);
416438
}
417439

418440
/**
@@ -840,6 +862,13 @@ private Collection<JID> setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
840862
List<JID> ownersToAdd = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners());
841863
allNewAffiliations.addAll(ownersToAdd);
842864
room.addOwners(ownersToAdd, room.getRole());
865+
if (mucRoomEntity.getOwnerGroups() != null) {
866+
for (final String groupName : mucRoomEntity.getOwnerGroups()) {
867+
final JID groupJID = UserUtils.checkAndGetJID(groupName);
868+
room.addOwner(groupJID, room.getRole());
869+
allNewAffiliations.add(groupJID);
870+
}
871+
}
843872

844873
// Admins
845874
if (mucRoomEntity.getAdmins() != null) {
@@ -848,6 +877,13 @@ private Collection<JID> setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
848877
allNewAffiliations.addAll(newAdmins);
849878
room.addAdmins(newAdmins, room.getRole());
850879
}
880+
if (mucRoomEntity.getAdminGroups() != null) {
881+
for (final String groupName : mucRoomEntity.getAdminGroups()) {
882+
final JID groupJID = UserUtils.checkAndGetJID(groupName);
883+
room.addAdmin(groupJID, room.getRole());
884+
allNewAffiliations.add(groupJID);
885+
}
886+
}
851887

852888
// Members
853889
if (mucRoomEntity.getMembers() != null) {
@@ -858,14 +894,26 @@ private Collection<JID> setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
858894
room.addMember(memberJid, null, room.getRole());
859895
}
860896
}
897+
if (mucRoomEntity.getMemberGroups() != null) {
898+
for (final String groupName : mucRoomEntity.getMemberGroups()) {
899+
final JID groupJID = UserUtils.checkAndGetJID(groupName);
900+
room.addMember(groupJID, null, room.getRole());
901+
allNewAffiliations.add(groupJID);
902+
}
903+
}
861904

862905
// Outcasts
863906
if (mucRoomEntity.getOutcasts() != null) {
864907
for (String outcastJid : mucRoomEntity.getOutcasts()) {
865908
room.addOutcast(new JID(outcastJid), null, room.getRole());
866909
}
867910
}
868-
911+
if (mucRoomEntity.getOutcastGroups() != null) {
912+
for (final String groupName : mucRoomEntity.getOutcastGroups()) {
913+
final JID groupJID = UserUtils.checkAndGetJID(groupName);
914+
room.addOutcast(groupJID, null, room.getRole());
915+
}
916+
}
869917
return allNewAffiliations;
870918
}
871919

0 commit comments

Comments
 (0)