예제 #1
0
  /**
   * Adds the group users of the given shared group to the roster of the specified user.
   *
   * @param group the shared group to add to the roster of a user.
   * @param username the name of the user to add a shared group to his roster.
   */
  private void addSharedGroupToRoster(Group group, String username) {
    // Get the group users to add to the user's roster
    Collection<String> users = new HashSet<String>(group.getMembers());
    users.addAll(group.getAdmins());

    // Get the roster of the user from which we need to add the shared group users
    Roster userRoster = (Roster) CacheManager.getCache("username2roster").get(username);

    // Iterate on all the group users and update their rosters
    for (String userToAdd : users) {
      // Get the roster to update
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToAdd);
      // Only update rosters in memory
      if (roster != null) {
        roster.addSharedUser(group, username);
      }
      // Update the roster of the user
      if (userRoster != null) {
        try {
          User user = UserManager.getInstance().getUser(userToAdd);
          Collection<Group> groups = GroupManager.getInstance().getGroups(user);
          userRoster.addSharedUser(userToAdd, groups, group);
        } catch (UserNotFoundException e) {
        }
      }
    }
  }
예제 #2
0
  /**
   * Notification that a Group user has been added. Update the group users' roster accordingly.
   *
   * @param group the group where the user was added.
   * @param addedUser the username of the user that has been added to the group.
   */
  private void groupUserAdded(Group group, String addedUser) {
    // Get all the affected users
    Collection<String> users = getAffectedUsers(group);
    // Get the roster of the added user.
    Roster addedUserRoster = (Roster) CacheManager.getCache("username2roster").get(addedUser);

    // Iterate on all the affected users and update their rosters
    for (String userToUpdate : users) {
      if (!addedUser.equals(userToUpdate)) {
        // Get the roster to update
        Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToUpdate);
        // Only update rosters in memory
        if (roster != null) {
          roster.addSharedUser(group, addedUser);
        }
        // Update the roster of the newly added group user.
        if (addedUserRoster != null) {
          try {
            User user = UserManager.getInstance().getUser(userToUpdate);
            Collection<Group> groups = GroupManager.getInstance().getGroups(user);
            addedUserRoster.addSharedUser(userToUpdate, groups, group);
          } catch (UserNotFoundException e) {
          }
        }
      }
    }
  }