Commit b362997c authored by Mike McCarthy's avatar Mike McCarthy Committed by michaelcmccarthy

OF-418 - Now the RosterItemProvider is an interface, we should really use that...

OF-418 - Now the RosterItemProvider is an interface, we should really use that provider's returned RosterItem, otherwise the create method may as well be void.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13349 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8042f232
......@@ -145,7 +145,7 @@ public class Roster implements Cacheable, Externalizable {
rosterItems.put(item.getJid().toBareJID(), item);
}
// Add RosterItems that belong only to shared groups
Map<JID,List<Group>> sharedUsers = getSharedUsers(sharedGroups);
Map<JID, List<Group>> sharedUsers = getSharedUsers(sharedGroups);
for (Map.Entry<JID, List<Group>> entry : sharedUsers.entrySet()) {
JID jid = entry.getKey();
List<Group> groups = entry.getValue();
......@@ -153,14 +153,13 @@ public class Roster implements Cacheable, Externalizable {
Collection<Group> itemGroups = new ArrayList<Group>();
String nickname = "";
RosterItem item = new RosterItem(jid, RosterItem.SUB_TO, RosterItem.ASK_NONE,
RosterItem.RECV_NONE, nickname , null);
RosterItem.RECV_NONE, nickname, null);
// Add the shared groups to the new roster item
for (Group group : groups) {
if (group.isUser(jid)) {
item.addSharedGroup(group);
itemGroups.add(group);
}
else {
} else {
item.addInvisibleSharedGroup(group);
}
}
......@@ -168,8 +167,7 @@ public class Roster implements Cacheable, Externalizable {
// that is mutually visible with a shared group of the new roster item
if (rosterManager.hasMutualVisibility(username, sharedGroups, jid, itemGroups)) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
else {
} else {
// Set subscription type to FROM if the contact does not belong to any of
// the associated shared groups
boolean belongsToGroup = false;
......@@ -191,14 +189,12 @@ public class Roster implements Cacheable, Externalizable {
if (item.getSubStatus() != RosterItem.SUB_FROM) {
item.setNickname(UserNameManager.getUserName(jid));
rosterItems.put(item.getJid().toBareJID(), item);
}
else {
} else {
// Cache information about shared contacts with subscription status FROM
implicitFrom
.put(item.getJid().toBareJID(), item.getInvisibleSharedGroupsNames());
}
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
Log.error("Groups (" + groups + ") include non-existent username (" +
jid.getNode() +
")");
......@@ -350,7 +346,7 @@ public class Roster implements Cacheable, Externalizable {
// Check if we need to make the new roster item persistent
if (persistent) {
rosterItemProvider.createItem(username, rosterItem);
rosterItem = rosterItemProvider.createItem(username, rosterItem);
}
if (push) {
......@@ -396,8 +392,7 @@ public class Roster implements Cacheable, Externalizable {
String defaultContactName;
try {
defaultContactName = UserNameManager.getUserName(item.getJid());
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
// Cannot update a roster item for a local user that does not exist
defaultContactName = item.getNickname();
}
......@@ -407,16 +402,13 @@ public class Roster implements Cacheable, Externalizable {
}
try {
rosterItemProvider.createItem(username, item);
}
catch (UserAlreadyExistsException e) {
} catch (UserAlreadyExistsException e) {
// Do nothing. We shouldn't be here.
}
}
else {
} else {
// Item is not persistent and it does not belong to a shared contact so do nothing
}
}
else {
} else {
// Update the backend data store
rosterItemProvider.updateItem(username, item);
}
......@@ -490,8 +482,7 @@ public class Roster implements Cacheable, Externalizable {
}
return item;
}
else {
} else {
// Verify if the item being removed is an implicit roster item
// that only exists due to some shared group
RosterItem item = getImplicitRosterItem(user);
......@@ -549,8 +540,7 @@ public class Roster implements Cacheable, Externalizable {
String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
groups.add(displayName);
}
else {
} else {
// Do not add the shared group if it does not have a displayName.
Log.warn("Found shared group: " + sharedGroup.getName() +
" with no displayName");
......@@ -611,8 +601,7 @@ public class Roster implements Cacheable, Externalizable {
for (JID jid : routingTable.getRoutes(searchNode, null)) {
try {
routingTable.routePacket(jid, packet, false);
}
catch (Exception e) {
} catch (Exception e) {
// Theoretically only happens if session has been closed.
Log.debug(e.getMessage(), e);
}
......@@ -623,7 +612,7 @@ public class Roster implements Cacheable, Externalizable {
for (String contact : implicitFrom.keySet()) {
if (contact.contains("@")) {
String node = contact.substring(0, contact.lastIndexOf("@"));
String domain = contact.substring(contact.lastIndexOf("@")+1);
String domain = contact.substring(contact.lastIndexOf("@") + 1);
node = JID.escapeNode(node);
contact = new JID(node, domain, null).toBareJID();
}
......@@ -633,11 +622,10 @@ public class Roster implements Cacheable, Externalizable {
// Outgoing presence notifications are blocked for this contact
continue;
}
for (JID jid: routingTable.getRoutes(new JID(contact), null)) {
for (JID jid : routingTable.getRoutes(new JID(contact), null)) {
try {
routingTable.routePacket(jid, packet, false);
}
catch (Exception e) {
} catch (Exception e) {
// Theoretically only happens if session has been closed.
Log.debug(e.getMessage(), e);
}
......@@ -656,10 +644,10 @@ public class Roster implements Cacheable, Externalizable {
* @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) {
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<JID,List<Group>>();
Map<JID, List<Group>> sharedGroupUsers = new HashMap<JID, List<Group>>();
for (Group group : sharedGroups) {
// Get all the users that should be in this roster
Collection<JID> users = rosterManager.getSharedUsersForRoster(group, this);
......@@ -743,7 +731,7 @@ public class Roster implements Cacheable, Externalizable {
size += CacheSizes.sizeOfString(username); // username
// implicitFrom
for(Map.Entry<String, Set<String>> entry : implicitFrom.entrySet()) {
for (Map.Entry<String, Set<String>> entry : implicitFrom.entrySet()) {
size += CacheSizes.sizeOfString(entry.getKey());
size += CacheSizes.sizeOfCollection(entry.getValue());
}
......@@ -773,8 +761,7 @@ public class Roster implements Cacheable, Externalizable {
return;
}
newItem = false;
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
try {
// Create a new RosterItem for this new user
String nickname = UserNameManager.getUserName(addedUser);
......@@ -784,8 +771,7 @@ public class Roster implements Cacheable, Externalizable {
// Add the new item to the list of items
rosterItems.put(item.getJid().toBareJID(), item);
newItem = true;
}
catch (UserNotFoundException ex) {
} catch (UserNotFoundException ex) {
Log.error("Group (" + group.getName() + ") includes non-existent username (" +
addedUser +
")");
......@@ -813,16 +799,14 @@ public class Roster implements Cacheable, Externalizable {
// user and this user
else if (group.isUser(addedUser) && !group.isUser(getUsername())) {
item.setSubStatus(RosterItem.SUB_TO);
}
else if (!group.isUser(addedUser) && group.isUser(getUsername())) {
} else if (!group.isUser(addedUser) && group.isUser(getUsername())) {
item.setSubStatus(RosterItem.SUB_FROM);
}
// Add the shared group to the list of shared groups
if (item.getSubStatus() != RosterItem.SUB_FROM) {
item.addSharedGroup(group);
}
else {
} else {
item.addInvisibleSharedGroup(group);
}
......@@ -832,8 +816,7 @@ public class Roster implements Cacheable, Externalizable {
if (prevSubscription == RosterItem.SUB_TO &&
item.getSubStatus() == RosterItem.SUB_FROM) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
else if (prevSubscription == RosterItem.SUB_FROM &&
} else if (prevSubscription == RosterItem.SUB_FROM &&
item.getSubStatus() == RosterItem.SUB_TO) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
......@@ -845,8 +828,7 @@ public class Roster implements Cacheable, Externalizable {
rosterItems.remove(item.getJid().toBareJID());
// Cache information about shared contacts with subscription status FROM
implicitFrom.put(item.getJid().toBareJID(), item.getInvisibleSharedGroupsNames());
}
else {
} else {
// Remove from list of shared contacts with status FROM (if any)
implicitFrom.remove(item.getJid().toBareJID());
// Ensure that the item is an explicit roster item
......@@ -862,8 +844,7 @@ public class Roster implements Cacheable, Externalizable {
if (newItem) {
// Fire event indicating that a roster item has been added
RosterEventDispatcher.contactAdded(this, item);
}
else {
} else {
// Fire event indicating that a roster item has been updated
RosterEventDispatcher.contactUpdated(this, item);
}
......@@ -884,8 +865,7 @@ public class Roster implements Cacheable, Externalizable {
// Get the RosterItem for the *local* user to add
item = getRosterItem(addedUser);
newItem = false;
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
try {
// Create a new RosterItem for this new user
String nickname = UserNameManager.getUserName(addedUser);
......@@ -895,8 +875,7 @@ public class Roster implements Cacheable, Externalizable {
// Add the new item to the list of items
rosterItems.put(item.getJid().toBareJID(), item);
newItem = true;
}
catch (UserNotFoundException ex) {
} catch (UserNotFoundException ex) {
Log.error("Couldn't find a user with username (" + addedUser + ")");
}
}
......@@ -922,8 +901,7 @@ public class Roster implements Cacheable, Externalizable {
item.addInvisibleSharedGroup(group);
}
}
}
else {
} else {
// If an item already exists then take note of the old subscription status
RosterItem.SubType prevSubscription = null;
if (!newItem) {
......@@ -951,8 +929,7 @@ public class Roster implements Cacheable, Externalizable {
if (prevSubscription == RosterItem.SUB_TO &&
item.getSubStatus() == RosterItem.SUB_FROM) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
else if (prevSubscription == RosterItem.SUB_FROM &&
} else if (prevSubscription == RosterItem.SUB_FROM &&
item.getSubStatus() == RosterItem.SUB_TO) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
......@@ -964,8 +941,7 @@ public class Roster implements Cacheable, Externalizable {
rosterItems.remove(item.getJid().toBareJID());
// Cache information about shared contacts with subscription status FROM
implicitFrom.put(item.getJid().toBareJID(), item.getInvisibleSharedGroupsNames());
}
else {
} else {
// Remove from list of shared contacts with status FROM (if any)
implicitFrom.remove(item.getJid().toBareJID());
// Ensure that the item is an explicit roster item
......@@ -981,8 +957,7 @@ public class Roster implements Cacheable, Externalizable {
if (newItem) {
// Fire event indicating that a roster item has been added
RosterEventDispatcher.contactAdded(this, item);
}
else {
} else {
// Fire event indicating that a roster item has been updated
RosterEventDispatcher.contactUpdated(this, item);
}
......@@ -1012,8 +987,7 @@ public class Roster implements Cacheable, Externalizable {
// Delete the roster item from the roster since it exists only because of this
// group which is being removed
deleteRosterItem(deletedUser, false);
}
else {
} else {
// Remove the removed shared group from the list of shared groups
item.removeSharedGroup(sharedGroup);
// Update the subscription of the item based on the remaining groups
......@@ -1027,23 +1001,19 @@ public class Roster implements Cacheable, Externalizable {
if (rosterManager.hasMutualVisibility(getUsername(), userGroups, deletedUser,
sharedGroups)) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
else if (item.getSharedGroups().isEmpty() &&
} else if (item.getSharedGroups().isEmpty() &&
!item.getInvisibleSharedGroups().isEmpty()) {
item.setSubStatus(RosterItem.SUB_FROM);
}
else {
} else {
item.setSubStatus(RosterItem.SUB_TO);
}
}
// Brodcast to all the user resources of the updated roster item
broadcast(item, false);
}
}
catch (SharedGroupException e) {
} catch (SharedGroupException e) {
// Do nothing. Checkings are disabled so this exception should never happen.
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
// Do nothing since the contact does not exist in the user's roster. (strange case!)
}
}
......@@ -1061,8 +1031,7 @@ public class Roster implements Cacheable, Externalizable {
// Delete the roster item from the roster since it exists only because of this
// group which is being removed
deleteRosterItem(deletedUser, false);
}
else {
} else {
// Remove the shared group from the item if deletedUser does not belong to a
// public group
if (!(deletedGroup.isUser(deletedUser) &&
......@@ -1088,8 +1057,7 @@ public class Roster implements Cacheable, Externalizable {
if (rosterManager
.hasMutualVisibility(getUsername(), userGroups, deletedUser, groups)) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
else {
} else {
// Assume by default that the contact has subscribed from the presence of
// this user
item.setSubStatus(RosterItem.SUB_FROM);
......@@ -1104,11 +1072,9 @@ public class Roster implements Cacheable, Externalizable {
// Brodcast to all the user resources of the updated roster item
broadcast(item, false);
}
}
catch (SharedGroupException e) {
} catch (SharedGroupException e) {
// Do nothing. Checkings are disabled so this exception should never happen.
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
// Do nothing since the contact does not exist in the user's roster. (strange case!)
}
}
......@@ -1131,8 +1097,7 @@ public class Roster implements Cacheable, Externalizable {
item = getRosterItem(user);
// Brodcast to all the user resources of the updated roster item
broadcast(item, true);
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
// Do nothing since the contact does not exist in the user's roster. (strange case!)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment