2020import org .jivesoftware .openfire .XMPPServer ;
2121import org .jivesoftware .openfire .group .ConcurrentGroupList ;
2222import org .jivesoftware .openfire .group .Group ;
23+ import org .jivesoftware .openfire .group .GroupJID ;
2324import org .jivesoftware .openfire .muc .*;
2425import org .jivesoftware .openfire .muc .spi .MUCRoomSearchInfo ;
2526import 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