use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class Roster method deleteSharedUser.
void deleteSharedUser(JID deletedUser, Group deletedGroup) {
try {
// Get the RosterItem for the *local* user to remove
RosterItem item = getRosterItem(deletedUser);
int groupSize = item.getSharedGroups().size() + item.getInvisibleSharedGroups().size();
if (item.isOnlyShared() && groupSize == 1 && // subcription status will change
!(deletedGroup.isUser(deletedUser) && RosterManager.isPublicSharedGroup(deletedGroup))) {
// Delete the roster item from the roster since it exists only because of this
// group which is being removed
deleteRosterItem(deletedUser, false);
} else {
// public group
if (!(deletedGroup.isUser(deletedUser) && RosterManager.isPublicSharedGroup(deletedGroup))) {
item.removeSharedGroup(deletedGroup);
}
// Get the groups of the deleted user
Collection<Group> groups = GroupManager.getInstance().getGroups(deletedUser);
// Remove all invalid shared groups from the roster item
for (Group group : groups) {
if (!rosterManager.isGroupVisible(group, getUserJID())) {
// Remove the shared group from the list of shared groups
item.removeSharedGroup(group);
}
}
// Update the subscription of the item **based on the item groups**
if (item.isOnlyShared()) {
Collection<Group> userGroups = GroupManager.getInstance().getGroups(getUserJID());
// that is mutually visible with a shared group of the new roster item
if (rosterManager.hasMutualVisibility(getUsername(), userGroups, deletedUser, groups)) {
item.setSubStatus(RosterItem.SUB_BOTH);
} else {
// Assume by default that the contact has subscribed from the presence of
// this user
item.setSubStatus(RosterItem.SUB_FROM);
// Check if the user may see the new contact in a shared group
for (Group group : groups) {
if (rosterManager.isGroupVisible(group, getUserJID())) {
item.setSubStatus(RosterItem.SUB_TO);
}
}
}
// Fire event indicating that a roster item has been updated
RosterEventDispatcher.contactUpdated(this, item);
} else {
// Fire event indicating that a roster item has been removed
RosterEventDispatcher.contactDeleted(this, item);
}
// Brodcast to all the user resources of the updated roster item
broadcast(item, false);
}
} catch (SharedGroupException e) {
// Do nothing. Checkings are disabled so this exception should never happen.
} catch (UserNotFoundException e) {
// Do nothing since the contact does not exist in the user's roster. (strange case!)
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class Roster method getSharedUsers.
/**
* Returns the list of users that belong ONLY to a shared group of this user. If the contact
* belongs to the personal roster and a shared group then it wont' be included in the answer.
*
* @param sharedGroups the shared groups of this user.
* @return the list of users that belong ONLY to a shared group of this user.
*/
private Map<JID, List<Group>> getSharedUsers(Collection<Group> sharedGroups) {
// Get the users to process from the shared groups. Users that belong to different groups
// will have one entry in the map associated with all the groups
Map<JID, List<Group>> sharedGroupUsers = new HashMap<>();
for (Group group : sharedGroups) {
// Get all the users that should be in this roster
Collection<JID> users = rosterManager.getSharedUsersForRoster(group, this);
// Add the users of the group to the general list of users to process
JID userJID = getUserJID();
for (JID jid : users) {
// Add the user to the answer if the user doesn't belong to the personal roster
// (since we have already added the user to the answer)
boolean isRosterItem = rosterItems.containsKey(jid.toBareJID());
if (!isRosterItem && !userJID.equals(jid)) {
List<Group> groups = sharedGroupUsers.get(jid);
if (groups == null) {
groups = new ArrayList<>();
sharedGroupUsers.put(jid, groups);
}
groups.add(group);
}
}
}
return sharedGroupUsers;
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class Roster method getReset.
/**
* <p>Obtain a 'roster reset', a snapshot of the full cached roster as an Roster.</p>
*
* @return The roster reset (snapshot) as an Roster
*/
public org.xmpp.packet.Roster getReset() {
org.xmpp.packet.Roster roster = new org.xmpp.packet.Roster();
// Add the roster items (includes the personal roster and shared groups) to the answer
for (RosterItem item : rosterItems.values()) {
// Do not include items with status FROM that exist only because of shared groups
if (item.isOnlyShared() && item.getSubStatus() == RosterItem.SUB_FROM) {
continue;
}
org.xmpp.packet.Roster.Ask ask = getAskStatus(item.getAskStatus());
org.xmpp.packet.Roster.Subscription sub = org.xmpp.packet.Roster.Subscription.valueOf(item.getSubStatus().getName());
// Set the groups to broadcast (include personal and shared groups)
List<String> groups = new ArrayList<>(item.getGroups());
if (groups.contains(null)) {
Log.warn("A group is null in roster item: " + item.getJid() + " of user: " + getUsername());
}
for (Group sharedGroup : item.getSharedGroups()) {
String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
groups.add(displayName);
} else {
// Do not add the shared group if it does not have a displayName.
Log.warn("Found shared group: " + sharedGroup.getName() + " with no displayName");
}
}
// Do not push items with a state of "None + Pending In"
if (item.getSubStatus() != RosterItem.SUB_NONE || item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE && !isSubscriptionRejected(item)) {
roster.addItem(item.getJid(), item.getNickname(), ask, sub, groups);
}
}
return roster;
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class Roster method broadcast.
/**
* Broadcasts the RosterItem to all the connected resources of this user. Due to performance
* optimizations and due to some clients errors that are showing items with subscription status
* FROM we added a flag that indicates if a roster items that exists only because of a shared
* group with subscription status FROM will not be sent.
*
* @param item the item to broadcast.
* @param optimize true indicates that items that exists only because of a shared
* group with subscription status FROM will not be sent
*/
public void broadcast(RosterItem item, boolean optimize) {
// Do not broadcast items with status FROM that exist only because of shared groups
if (optimize && item.isOnlyShared() && item.getSubStatus() == RosterItem.SUB_FROM) {
return;
}
// Set the groups to broadcast (include personal and shared groups)
List<String> groups = new ArrayList<>(item.getGroups());
for (Group sharedGroup : item.getSharedGroups()) {
String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
groups.add(displayName);
}
}
org.xmpp.packet.Roster roster = new org.xmpp.packet.Roster();
roster.setType(IQ.Type.set);
roster.addItem(item.getJid(), item.getNickname(), getAskStatus(item.getAskStatus()), org.xmpp.packet.Roster.Subscription.valueOf(item.getSubStatus().getName()), groups);
broadcast(roster);
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class RosterManager method groupUserAdded.
/**
* Notification that a Group user has been added. Update the group users' roster accordingly.
*
* @param group the group where the user was added.
* @param users the users to update their rosters
* @param addedUser the username of the user that has been added to the group.
*/
private void groupUserAdded(Group group, Collection<JID> users, JID addedUser) {
// Get the roster of the added user.
Roster addedUserRoster = null;
if (server.isLocal(addedUser)) {
addedUserRoster = rosterCache.get(addedUser.getNode());
}
// Iterate on all the affected users and update their rosters
for (JID userToUpdate : users) {
if (!addedUser.equals(userToUpdate)) {
// Get the roster to update
Roster roster = null;
if (server.isLocal(userToUpdate)) {
// Check that the user exists, if not then continue with the next user
try {
UserManager.getInstance().getUser(userToUpdate.getNode());
} catch (UserNotFoundException e) {
continue;
}
roster = rosterCache.get(userToUpdate.getNode());
}
// Only update rosters in memory
if (roster != null) {
roster.addSharedUser(group, addedUser);
}
// Check if the roster is still not in memory
if (addedUserRoster == null && server.isLocal(addedUser)) {
addedUserRoster = rosterCache.get(addedUser.getNode());
}
// Update the roster of the newly added group user.
if (addedUserRoster != null) {
Collection<Group> groups = GroupManager.getInstance().getGroups(userToUpdate);
addedUserRoster.addSharedUser(userToUpdate, groups, group);
}
if (!server.isLocal(addedUser)) {
// Susbcribe to the presence of the remote user. This is only necessary for
// remote users and may only work with remote users that **automatically**
// accept presence subscription requests
sendSubscribeRequest(userToUpdate, addedUser, true);
}
if (!server.isLocal(userToUpdate)) {
// Susbcribe to the presence of the remote user. This is only necessary for
// remote users and may only work with remote users that **automatically**
// accept presence subscription requests
sendSubscribeRequest(addedUser, userToUpdate, true);
}
}
}
}
Aggregations