Skip to content

Commit

Permalink
#128 Do not send new invitations for unmodified affiliations when upd…
Browse files Browse the repository at this point in the history
…ating a room
  • Loading branch information
evdherberg authored and guusdk committed Aug 2, 2022
1 parent 82a31ee commit adce6ea
Showing 1 changed file with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName, boolean
} else {
room.setRolesToBroadcastPresence(new ArrayList<>());
}

// Set all roles
Collection<JID> allUsersWithNewAffiliations = null;
if (!equalToAffiliations(room, mucRoomEntity)) {
setRoles(room, mucRoomEntity);
allUsersWithNewAffiliations = setRoles(room, mucRoomEntity);
}

// Set creation date
Expand All @@ -389,8 +391,8 @@ private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName, boolean

MUCServiceController.getService(serviceName).syncChatRoom(room);

if (sendInvitations) {
sendInvitationsFromRoom(room, null, null, null, true);
if (sendInvitations && allUsersWithNewAffiliations != null) {
sendInvitationsFromRoom(room, null, allUsersWithNewAffiliations, null, true);
}
}

Expand Down Expand Up @@ -795,15 +797,19 @@ public MUCRoomEntity convertToMUCRoomEntity(MUCRoom room, boolean expand) {
* the room
* @param mucRoomEntity
* the muc room entity
* @return
* all users for which a role was added
* @throws ForbiddenException
* the forbidden exception
* @throws NotAllowedException
* the not allowed exception
* @throws ConflictException
* the conflict exception
*/
private void setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws ForbiddenException, NotAllowedException,
private Collection<JID> setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws ForbiddenException, NotAllowedException,
ConflictException {
Collection<JID> allNewAffiliations = new ArrayList<>();

List<JID> roles = new ArrayList<>();
Collection<JID> existingOwners = new ArrayList<>();

Expand All @@ -819,7 +825,6 @@ private void setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws Forbidde

// Don't delete the same owners
owners.removeAll(existingOwners);
room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());

// Collect all roles to reset
roles.addAll(owners);
Expand All @@ -831,20 +836,37 @@ private void setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws Forbidde
room.addNone(jid, room.getRole());
}

room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());
// Owners
List<JID> ownersToAdd = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners());
allNewAffiliations.addAll(ownersToAdd);
room.addOwners(ownersToAdd, room.getRole());

// Admins
if (mucRoomEntity.getAdmins() != null) {
room.addAdmins(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getAdmins()), room.getRole());
List<JID> newAdmins = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getAdmins());
newAdmins.removeAll(room.getAdmins());
allNewAffiliations.addAll(newAdmins);
room.addAdmins(newAdmins, room.getRole());
}

// Members
if (mucRoomEntity.getMembers() != null) {
for (String memberJid : mucRoomEntity.getMembers()) {
room.addMember(new JID(memberJid), null, room.getRole());
List<JID> newMembers = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getMembers());
newMembers.removeAll(room.getMembers());
allNewAffiliations.addAll(newMembers);
for (JID memberJid : newMembers) {
room.addMember(memberJid, null, room.getRole());
}
}

// Outcasts
if (mucRoomEntity.getOutcasts() != null) {
for (String outcastJid : mucRoomEntity.getOutcasts()) {
room.addOutcast(new JID(outcastJid), null, room.getRole());
}
}

return allNewAffiliations;
}

/**
Expand Down

0 comments on commit adce6ea

Please sign in to comment.