Commit 906a4623 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Subscription status is now calculated correctly for existing roster items when...

Subscription status is now calculated correctly for existing roster items when a new member is added to a shared group. JM-451

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@3029 b35dd754-fafc-0310-a699-88a17e54d16e
parent af3ab023
...@@ -603,35 +603,40 @@ public class Roster implements Cacheable { ...@@ -603,35 +603,40 @@ public class Roster implements Cacheable {
")"); ")");
} }
} }
// If an item already exists then take note of the old subscription status
RosterItem.SubType prevSubscription = null;
if (!newItem) {
prevSubscription = item.getSubStatus();
}
// Update the subscription of the item **based on the item groups** // Update the subscription of the item **based on the item groups**
if (newItem || item.isOnlyShared()) { Collection<Group> userGroups = null;
Collection<Group> userGroups = null; Collection<Group> sharedGroups = new ArrayList<Group>();
Collection<Group> sharedGroups = new ArrayList<Group>(); try {
try { User rosterUser = UserManager.getInstance().getUser(getUsername());
User rosterUser = UserManager.getInstance().getUser(getUsername()); GroupManager groupManager = GroupManager.getInstance();
GroupManager groupManager = GroupManager.getInstance(); userGroups = groupManager.getGroups(rosterUser);
userGroups = groupManager.getGroups(rosterUser); sharedGroups.addAll(item.getSharedGroups());
sharedGroups.addAll(item.getSharedGroups()); // Add the new group to the list of groups to check
// Add the new group to the list of groups to check sharedGroups.add(group);
sharedGroups.add(group); // Set subscription type to BOTH if the roster user belongs to a shared group
// Set subscription type to BOTH if the roster user belongs to a shared group // that is mutually visible with a shared group of the new roster item
// that is mutually visible with a shared group of the new roster item if (rosterManager.hasMutualVisibility(getUsername(), userGroups, jid.getNode(),
if (rosterManager.hasMutualVisibility(getUsername(), userGroups, jid.getNode(), sharedGroups)) {
sharedGroups)) { item.setSubStatus(RosterItem.SUB_BOTH);
item.setSubStatus(RosterItem.SUB_BOTH);
}
// Update the subscription status depending on the group membership of the new
// 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())) {
item.setSubStatus(RosterItem.SUB_FROM);
}
} }
catch (UserNotFoundException e) { // Update the subscription status depending on the group membership of the new
// 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())) {
item.setSubStatus(RosterItem.SUB_FROM);
} }
} }
catch (UserNotFoundException e) {
}
// Add the shared group to the list of shared groups // Add the shared group to the list of shared groups
if (item.getSubStatus() != RosterItem.SUB_FROM) { if (item.getSubStatus() != RosterItem.SUB_FROM) {
...@@ -640,6 +645,20 @@ public class Roster implements Cacheable { ...@@ -640,6 +645,20 @@ public class Roster implements Cacheable {
else { else {
item.addInvisibleSharedGroup(group); item.addInvisibleSharedGroup(group);
} }
// If the item already exists then check if the subscription status should be
// changed to BOTH based on the old and new subscription status
if (prevSubscription != null) {
if (prevSubscription == RosterItem.SUB_TO &&
item.getSubStatus() == RosterItem.SUB_FROM) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
else if (prevSubscription == RosterItem.SUB_FROM &&
item.getSubStatus() == RosterItem.SUB_TO) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
}
// Brodcast to all the user resources of the updated roster item // Brodcast to all the user resources of the updated roster item
broadcast(item, true); broadcast(item, true);
// Probe the presence of the new group user // Probe the presence of the new group user
...@@ -682,54 +701,71 @@ public class Roster implements Cacheable { ...@@ -682,54 +701,71 @@ public class Roster implements Cacheable {
} }
} }
// Update the subscription of the item **based on the item groups** // Update the subscription of the item **based on the item groups**
if (newItem || item.isOnlyShared()) { Collection<Group> userGroups = null;
Collection<Group> userGroups = null; try {
try { User rosterUser = UserManager.getInstance().getUser(getUsername());
User rosterUser = UserManager.getInstance().getUser(getUsername()); GroupManager groupManager = GroupManager.getInstance();
GroupManager groupManager = GroupManager.getInstance(); userGroups = groupManager.getGroups(rosterUser);
userGroups = groupManager.getGroups(rosterUser); // Set subscription type to BOTH if the roster user belongs to a shared group
// Set subscription type to BOTH if the roster user belongs to a shared group // that is mutually visible with a shared group of the new roster item
// that is mutually visible with a shared group of the new roster item if (rosterManager.hasMutualVisibility(getUsername(), userGroups, jid.getNode(),
if (rosterManager.hasMutualVisibility(getUsername(), userGroups, jid.getNode(), groups)) {
groups)) { item.setSubStatus(RosterItem.SUB_BOTH);
item.setSubStatus(RosterItem.SUB_BOTH); for (Group group : groups) {
for (Group group : groups) { if (rosterManager.isGroupVisible(group, getUsername())) {
if (rosterManager.isGroupVisible(group, getUsername())) { // Add the shared group to the list of shared groups
// Add the shared group to the list of shared groups item.addSharedGroup(group);
item.addSharedGroup(group);
}
} }
// Add to the item the groups of this user that generated a FROM subscription }
// Note: This FROM subscription is overridden by the BOTH subscription but in // Add to the item the groups of this user that generated a FROM subscription
// fact there is a TO-FROM relation between these two users that ends up in a // Note: This FROM subscription is overridden by the BOTH subscription but in
// BOTH subscription // fact there is a TO-FROM relation between these two users that ends up in a
for (Group group : userGroups) { // BOTH subscription
if (!group.isUser(addedUser) && for (Group group : userGroups) {
rosterManager.isGroupVisible(group, addedUser)) { if (!group.isUser(addedUser) &&
// Add the shared group to the list of invisible shared groups rosterManager.isGroupVisible(group, addedUser)) {
item.addInvisibleSharedGroup(group); // Add the shared group to the list of invisible shared groups
} item.addInvisibleSharedGroup(group);
} }
} }
else { }
// Assume by default that the contact has subscribed from the presence of else {
// this user // If an item already exists then take note of the old subscription status
item.setSubStatus(RosterItem.SUB_FROM); RosterItem.SubType prevSubscription = null;
// Check if the user may see the new contact in a shared group if (!newItem) {
for (Group group : groups) { prevSubscription = item.getSubStatus();
if (rosterManager.isGroupVisible(group, getUsername())) { }
// Add the shared group to the list of shared groups
item.addSharedGroup(group); // Assume by default that the contact has subscribed from the presence of
item.setSubStatus(RosterItem.SUB_TO); // 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, getUsername())) {
// Add the shared group to the list of shared groups
item.addSharedGroup(group);
item.setSubStatus(RosterItem.SUB_TO);
} }
if (item.getSubStatus() == RosterItem.SUB_FROM) { }
item.addInvisibleSharedGroup(addedGroup); if (item.getSubStatus() == RosterItem.SUB_FROM) {
item.addInvisibleSharedGroup(addedGroup);
}
// If the item already exists then check if the subscription status should be
// changed to BOTH based on the old and new subscription status
if (prevSubscription != null) {
if (prevSubscription == RosterItem.SUB_TO &&
item.getSubStatus() == RosterItem.SUB_FROM) {
item.setSubStatus(RosterItem.SUB_BOTH);
}
else if (prevSubscription == RosterItem.SUB_FROM &&
item.getSubStatus() == RosterItem.SUB_TO) {
item.setSubStatus(RosterItem.SUB_BOTH);
} }
} }
} }
catch (UserNotFoundException e) { }
} catch (UserNotFoundException e) {
} }
// Brodcast to all the user resources of the updated roster item // Brodcast to all the user resources of the updated roster item
broadcast(item, true); broadcast(item, true);
......
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