Collection<JID> getSharedUsersForRoster(Group group, Roster roster) {
        SharedGroupVisibility showInRoster = group.getSharedWith();
        List<String> groupNames = group.getSharedWithUsersInGroupNames();

        // Answer an empty collection if the group is not being shown in users' rosters
        if (SharedGroupVisibility.usersOfGroups != showInRoster && SharedGroupVisibility.everybody != showInRoster) {
            return new ArrayList<>();
        }

        // Add the users of the group
        Collection<JID> users = new HashSet<>(group.getMembers());
        users.addAll(group.getAdmins());

        // If the user of the roster belongs to the shared group then we should return
        // users that need to be in the roster with subscription "from"
        if (group.isUser(roster.getUsername())) {
            // Check if anyone can see this shared group
            if (SharedGroupVisibility.everybody == showInRoster) {
                // Add all users in the system
                for (String username : UserManager.getInstance().getUsernames()) {
                    users.add(server.createJID(username, null, true));
                }
            }
            else {
                // Add the users that may see the group
                Collection<Group> groupList = parseGroups(groupNames);
                for (Group groupInList : groupList) {
                    users.addAll(groupInList.getMembers());
                    users.addAll(groupInList.getAdmins());
                }
            }
        }
        return users;
    }
This method is similar to {@link #getAffectedUsers(Group)} except that it receives
some group properties. The group properties are passed as parameters since the called of this
method may want to obtain the related users of the group based in some properties values.

This is useful when the group is being edited and some properties has changed and we need to
obtain the related users of the group based on the previous group state.
xmppserver/src/main/java/org/jivesoftware/openfire/roster/RosterManager.java