Skip to content

Commit

Permalink
fixes #136: Implement group role handling when creating/updating a room
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guusdk authored and Fishbowler committed Aug 4, 2022
1 parent 13bac32 commit e2fb14f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h1>
<p><b>1.9.0</b> (tbd)</p>
<ul>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/141'>#141</a>] - Remove boilerplate code for managing MUC room affiliations</li>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/136'>#136</a>] - Implement group role handling when creating/updating a room</li>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/130'>#130</a>] - Add endpoint to create a new MUC service</li>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/129'>#129</a>] - Add endpoint(s) to invite users to a chatroom</li>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -400,19 +401,40 @@ private boolean equalToAffiliations(MUCRoom room, MUCRoomEntity mucRoomEntity) {
if (mucRoomEntity == null || room == null) {
return false;
}
Set<String> admins = mucRoomEntity.getAdmins() != null ? new HashSet<>(mucRoomEntity.getAdmins()) : new HashSet<>();
Set<String> owners = mucRoomEntity.getOwners() != null ? new HashSet<>(mucRoomEntity.getOwners()) : new HashSet<>();
Set<String> members = mucRoomEntity.getMembers() != null ? new HashSet<>(mucRoomEntity.getMembers()) : new HashSet<>();
Set<String> outcasts = mucRoomEntity.getOutcasts() != null ? new HashSet<>(mucRoomEntity.getOutcasts()) : new HashSet<>();

Set<String> roomAdmins = room.getAdmins() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getAdmins())) : new HashSet<>();
Set<String> roomOwners = room.getOwners() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getOwners())) : new HashSet<>();
Set<String> roomMembers = room.getMembers() != null ? new HashSet<>(MUCRoomUtils.convertJIDsToStringList(room.getMembers())) : new HashSet<>();
Set<String> 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<JID> owners = new ConcurrentGroupList<>(room.getOwners());
ConcurrentGroupList<JID> admins = new ConcurrentGroupList<>(room.getAdmins());
ConcurrentGroupList<JID> members = new ConcurrentGroupList<>(room.getMembers());
ConcurrentGroupList<JID> outcasts = new ConcurrentGroupList<>(room.getOutcasts());

Set<String> roomOwners = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(owners)); // convertJIDsToStringList ignores group JIDs.
Set<String> roomAdmins = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(admins));
Set<String> roomMembers = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(members));
Set<String> roomOutcasts = new HashSet<>(MUCRoomUtils.convertJIDsToStringList(outcasts));

Set<String> entityOwners = mucRoomEntity.getOwners() != null ? new HashSet<>(mucRoomEntity.getOwners()) : new HashSet<>();
Set<String> entityAdmins = mucRoomEntity.getAdmins() != null ? new HashSet<>(mucRoomEntity.getAdmins()) : new HashSet<>();
Set<String> entityMembers = mucRoomEntity.getMembers() != null ? new HashSet<>(mucRoomEntity.getMembers()) : new HashSet<>();
Set<String> entityOutcasts = mucRoomEntity.getOutcasts() != null ? new HashSet<>(mucRoomEntity.getOutcasts()) : new HashSet<>();

Set<String> roomOwnerGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(owners.getGroups()));
Set<String> roomAdminGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(admins.getGroups()));
Set<String> roomMemberGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(members.getGroups()));
Set<String> roomOutcastGroups = new HashSet<>(MUCRoomUtils.convertGroupsToStringList(outcasts.getGroups()));

Set<String> entityOwnerGroups = mucRoomEntity.getOwnerGroups() != null ? new HashSet<>(mucRoomEntity.getOwnerGroups()) : new HashSet<>();
Set<String> entityAdminGroups = mucRoomEntity.getAdminGroups() != null ? new HashSet<>(mucRoomEntity.getAdminGroups()) : new HashSet<>();
Set<String> entityMemberGroups = mucRoomEntity.getMemberGroups() != null ? new HashSet<>(mucRoomEntity.getMemberGroups()) : new HashSet<>();
Set<String> 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);
}

/**
Expand Down Expand Up @@ -840,6 +862,13 @@ private Collection<JID> setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) thro
List<JID> 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) {
Expand All @@ -848,6 +877,13 @@ private Collection<JID> 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) {
Expand All @@ -858,14 +894,26 @@ private Collection<JID> 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) {
for (String outcastJid : mucRoomEntity.getOutcasts()) {
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;
}

Expand Down

0 comments on commit e2fb14f

Please sign in to comment.