Search in sources :

Example 26 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method getSharedUsersForRoster.

Collection<JID> getSharedUsersForRoster(Group group, Roster roster) {
    String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
    String groupNames = group.getProperties().get("sharedRoster.groupList");
    // Answer an empty collection if the group is not being shown in users' rosters
    if (!"onlyGroup".equals(showInRoster) && !"everybody".equals(showInRoster)) {
        return new ArrayList<>();
    }
    // Add the users of the group
    Collection<JID> users = new HashSet<>(group.getMembers());
    users.addAll(group.getAdmins());
    // 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 ("everybody".equals(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;
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Example 27 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method adminRemoved.

@Override
public void adminRemoved(Group group, Map params) {
    JID deletedUser = new JID((String) params.get("admin"));
    // Do nothing if the user is still a member
    if (group.getMembers().contains(deletedUser)) {
        return;
    }
    // Do nothing if the group is not being shown in group members' rosters
    if (!isSharedGroup(group)) {
        for (Group visibleGroup : getVisibleGroups(group)) {
            // Get the list of affected users
            Collection<JID> users = new HashSet<>(visibleGroup.getMembers());
            users.addAll(visibleGroup.getAdmins());
            groupUserDeleted(visibleGroup, users, deletedUser);
        }
    } else {
        groupUserDeleted(group, deletedUser);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Example 28 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method userModified.

@Override
public void userModified(User user, Map<String, Object> params) {
    if ("nameModified".equals(params.get("type"))) {
        for (Group group : getSharedGroups(user.getUsername())) {
            ArrayList<JID> groupUsers = new ArrayList<>();
            groupUsers.addAll(group.getAdmins());
            groupUsers.addAll(group.getMembers());
            for (JID groupUser : groupUsers) {
                rosterCache.remove(groupUser.getNode());
            }
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Example 29 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method getSharedGroups.

/**
 * Returns a collection with all the groups that the user may include in his roster. The
 * following criteria will be used to select the groups: 1) Groups that are configured so that
 * everybody can include in his roster, 2) Groups that are configured so that its users may
 * include the group in their rosters and the user is a group user of the group and 3) User
 * belongs to a Group that may see a Group that whose members may include the Group in their
 * rosters.
 *
 * @param username the username of the user to return his shared groups.
 * @return a collection with all the groups that the user may include in his roster.
 */
public Collection<Group> getSharedGroups(String username) {
    Collection<Group> answer = new HashSet<>();
    Collection<Group> groups = GroupManager.getInstance().getSharedGroups(username);
    for (Group group : groups) {
        String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
        if ("onlyGroup".equals(showInRoster)) {
            if (group.isUser(username)) {
                // The user belongs to the group so add the group to the answer
                answer.add(group);
            } else {
                // Check if the user belongs to a group that may see this group
                Collection<Group> groupList = parseGroups(group.getProperties().get("sharedRoster.groupList"));
                for (Group groupInList : groupList) {
                    if (groupInList.isUser(username)) {
                        answer.add(group);
                    }
                }
            }
        } else if ("everybody".equals(showInRoster)) {
            // Anyone can see this group so add the group to the answer
            answer.add(group);
        }
    }
    return answer;
}
Also used : Group(org.jivesoftware.openfire.group.Group)

Example 30 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method memberAdded.

@Override
public void memberAdded(Group group, Map params) {
    JID addedUser = new JID((String) params.get("member"));
    // Do nothing if the user was an admin that became a member
    if (group.getAdmins().contains(addedUser)) {
        return;
    }
    if (!isSharedGroup(group)) {
        for (Group visibleGroup : getVisibleGroups(group)) {
            // Get the list of affected users
            Collection<JID> users = new HashSet<>(visibleGroup.getMembers());
            users.addAll(visibleGroup.getAdmins());
            groupUserAdded(visibleGroup, users, addedUser);
        }
    } else {
        groupUserAdded(group, addedUser);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Aggregations

Group (org.jivesoftware.openfire.group.Group)84 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)42 JID (org.xmpp.packet.JID)30 Element (org.dom4j.Element)20 ArrayList (java.util.ArrayList)19 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)11 User (org.jivesoftware.openfire.user.User)9 List (java.util.List)7 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)7 StringTokenizer (java.util.StringTokenizer)6 GroupManager (org.jivesoftware.openfire.group.GroupManager)5 HashMap (java.util.HashMap)4 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)4 DataForm (org.xmpp.forms.DataForm)4 IQ (org.xmpp.packet.IQ)4 HashSet (java.util.HashSet)3 XMPPServer (org.jivesoftware.openfire.XMPPServer)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2