Commit a0c1a165 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

1. Show the shared group to a list of other groups. (still incomplete) JM-119

2. Show shared group in everyone's roster. JM-118


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@864 b35dd754-fafc-0310-a699-88a17e54d16e
parent 46a39fcb
...@@ -721,9 +721,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen ...@@ -721,9 +721,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
private void copyUserSessions(List sessions) { private void copyUserSessions(List sessions) {
// Get a copy of the sessions from all users // Get a copy of the sessions from all users
Iterator users = getSessionUsers(); for (String username : getSessionUsers()) {
while (users.hasNext()) { Collection<Session> usrSessions = getSessions(username);
Collection<Session> usrSessions = getSessions((String)users.next());
for (Session session : usrSessions) { for (Session session : usrSessions) {
sessions.add(session); sessions.add(session);
} }
...@@ -759,9 +758,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen ...@@ -759,9 +758,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
public int getSessionCount() { public int getSessionCount() {
int sessionCount = 0; int sessionCount = 0;
Iterator users = getSessionUsers(); for (String username : getSessionUsers()) {
while (users.hasNext()) { sessionCount += getSessionCount(username);
sessionCount += getSessionCount((String)users.next());
} }
sessionCount += anonymousSessions.size(); sessionCount += anonymousSessions.size();
return sessionCount; return sessionCount;
...@@ -780,8 +778,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen ...@@ -780,8 +778,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
return sessionCount; return sessionCount;
} }
public Iterator getSessionUsers() { public Collection<String> getSessionUsers() {
return Arrays.asList(sessions.keySet().toArray()).iterator(); return Collections.unmodifiableCollection(sessions.keySet());
} }
/** /**
......
...@@ -73,13 +73,7 @@ public class Roster implements Cacheable { ...@@ -73,13 +73,7 @@ public class Roster implements Cacheable {
Collection<Group> sharedGroups = null; Collection<Group> sharedGroups = null;
try { try {
User rosterUser = UserManager.getInstance().getUser(getUsername()); User rosterUser = UserManager.getInstance().getUser(getUsername());
sharedGroups = GroupManager.getInstance().getGroups(rosterUser); sharedGroups = XMPPServer.getInstance().getRosterManager().getSharedGroups(rosterUser);
// Remove groups that are not being shown in group members' rosters
for (Iterator<Group> it=sharedGroups.iterator(); it.hasNext();) {
if (!"true".equals(it.next().getProperties().get("showInRoster"))) {
it.remove();
}
}
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
sharedGroups = new ArrayList<Group>(); sharedGroups = new ArrayList<Group>();
...@@ -95,22 +89,32 @@ public class Roster implements Cacheable { ...@@ -95,22 +89,32 @@ public class Roster implements Cacheable {
for (Group group : sharedGroups) { for (Group group : sharedGroups) {
if (group.isUser(item.getJid().getNode())) { if (group.isUser(item.getJid().getNode())) {
// TODO Group name conflicts are not being considered (do we need this?) // TODO Group name conflicts are not being considered (do we need this?)
item.addSharedGroup(group.getProperties().get("displayName")); item.addSharedGroup(group.getProperties().get("sharedRoster.displayName"));
} }
} }
rosterItems.put(item.getJid().toBareJID(), item); rosterItems.put(item.getJid().toBareJID(), item);
} }
// Add RosterItems that belong only to shared groups // Add RosterItems that belong only to shared groups
Map<JID,List<String>> sharedUsers = getSharedUsers(sharedGroups); Map<JID,List<Group>> sharedUsers = getSharedUsers(sharedGroups);
for (JID jid : sharedUsers.keySet()) { for (JID jid : sharedUsers.keySet()) {
try { try {
RosterItem.SubType type = RosterItem.SUB_TO;
User user = UserManager.getInstance().getUser(jid.getNode()); User user = UserManager.getInstance().getUser(jid.getNode());
String nickname = "".equals(user.getName()) ? jid.getNode() : user.getName(); String nickname = "".equals(user.getName()) ? jid.getNode() : user.getName();
RosterItem item = new RosterItem(jid, RosterItem.SUB_BOTH, RosterItem.ASK_NONE, RosterItem item = new RosterItem(jid, RosterItem.SUB_BOTH, RosterItem.ASK_NONE,
RosterItem.RECV_NONE, nickname , null); RosterItem.RECV_NONE, nickname , null);
for (String group : sharedUsers.get(jid)) { if (sharedUsers.get(jid).isEmpty()) {
item.addSharedGroup(group); type = RosterItem.SUB_FROM;
}
else {
for (Group group : sharedUsers.get(jid)) {
item.addSharedGroup(group.getProperties().get("sharedRoster.displayName"));
if (group.isUser(username)) {
type = RosterItem.SUB_BOTH;
}
}
} }
item.setSubStatus(type);
rosterItems.put(item.getJid().toBareJID(), item); rosterItems.put(item.getJid().toBareJID(), item);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
...@@ -231,7 +235,7 @@ public class Roster implements Cacheable { ...@@ -231,7 +235,7 @@ public class Roster implements Cacheable {
Collection<Group> sharedGroups = GroupManager.getInstance().getGroups(); Collection<Group> sharedGroups = GroupManager.getInstance().getGroups();
for (String group : groups) { for (String group : groups) {
for (Group sharedGroup : sharedGroups) { for (Group sharedGroup : sharedGroups) {
if (group.equals(sharedGroup.getProperties().get("displayName"))) { if (group.equals(sharedGroup.getProperties().get("sharedRoster.displayName"))) {
throw new SharedGroupException("Cannot add an item to a shared group"); throw new SharedGroupException("Cannot add an item to a shared group");
} }
} }
...@@ -400,26 +404,29 @@ public class Roster implements Cacheable { ...@@ -400,26 +404,29 @@ public class Roster implements Cacheable {
* @param sharedGroups the shared groups of this user. * @param sharedGroups the shared groups of this user.
* @return the list of users that belong ONLY to a shared group of this user. * @return the list of users that belong ONLY to a shared group of this user.
*/ */
private Map<JID,List<String>> 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 // 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 // will have one entry in the map associated with all the groups
Map<JID,List<String>> sharedGroupUsers = new HashMap<JID,List<String>>(); Map<JID,List<Group>> sharedGroupUsers = new HashMap<JID,List<Group>>();
for (Group group : sharedGroups) { for (Group group : sharedGroups) {
// Get all the group users // Get all the users that can have this group in their rosters
Collection<String> users = new ArrayList<String>(group.getMembers()); Collection<String> users = XMPPServer.getInstance().getRosterManager().getRelatedUsers(group, false);
users.addAll(group.getAdmins());
// Add the users of the group to the general list of users to process // Add the users of the group to the general list of users to process
for (String groupUser : users) { for (String user : users) {
// Add the user to the answer if the user doesn't belong to the personal roster // 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) // (since we have already added the user to the answer)
JID jid = XMPPServer.getInstance().createJID(groupUser, null); JID jid = XMPPServer.getInstance().createJID(user, null);
if (!isRosterItem(jid) && !getUsername().equals(groupUser)) { if (!isRosterItem(jid) && !getUsername().equals(user)) {
List<String> groups = sharedGroupUsers.get(jid); List<Group> groups = sharedGroupUsers.get(jid);
if (groups == null) { if (groups == null) {
groups = new ArrayList<String>(); groups = new ArrayList<Group>();
sharedGroupUsers.put(jid, groups); sharedGroupUsers.put(jid, groups);
} }
groups.add(group.getProperties().get("displayName")); // Only associate the group with the user if the user is an actual user of
// the group
if (group.isUser(user)) {
groups.add(group);
}
} }
} }
} }
...@@ -475,17 +482,19 @@ public class Roster implements Cacheable { ...@@ -475,17 +482,19 @@ public class Roster implements Cacheable {
* group will be added to the shared groups lists. In any case an update broadcast will be sent * group will be added to the shared groups lists. In any case an update broadcast will be sent
* to all the users logged resources. * to all the users logged resources.
* *
* @param sharedGroup the shared group where the user was added. * @param group the shared group where the user was added.
* @param addedUser the contact to update in the roster. * @param addedUser the contact to update in the roster.
*/ */
void addSharedUser(String sharedGroup, String addedUser) { void addSharedUser(Group group, String addedUser) {
RosterItem item = null; RosterItem item = null;
JID jid = XMPPServer.getInstance().createJID(addedUser, ""); JID jid = XMPPServer.getInstance().createJID(addedUser, "");
// Get the display name of the group
String groupName = group.getProperties().get("sharedRoster.displayName");
try { try {
// Get the RosterItem for the *local* user to add // Get the RosterItem for the *local* user to add
item = getRosterItem(jid); item = getRosterItem(jid);
// Do nothing if the item already includes the shared group // Do nothing if the item already includes the shared group
if (item.getSharedGroups().contains(sharedGroup)) { if (item.getSharedGroups().contains(groupName)) {
return; return;
} }
} }
...@@ -501,17 +510,31 @@ public class Roster implements Cacheable { ...@@ -501,17 +510,31 @@ public class Roster implements Cacheable {
rosterItems.put(item.getJid().toBareJID(), item); rosterItems.put(item.getJid().toBareJID(), item);
} }
catch (UserNotFoundException ex) { catch (UserNotFoundException ex) {
Log.error("Group (" + sharedGroup + ") includes non-existent username (" + Log.error("Group (" + groupName + ") includes non-existent username (" +
addedUser + addedUser +
")"); ")");
} }
} }
// Add the shared group to the list of shared groups // Update the subscription status depending on the group membership of the new user and
item.addSharedGroup(sharedGroup); // this user
if (group.isUser(addedUser) && !group.isUser(getUsername())) {
item.setSubStatus(RosterItem.SUB_TO);
// Add the shared group to the list of shared groups
item.addSharedGroup(groupName);
}
else if (!group.isUser(addedUser) && group.isUser(getUsername())) {
item.setSubStatus(RosterItem.SUB_FROM);
}
else {
// Add the shared group to the list of shared groups
item.addSharedGroup(groupName);
}
// Brodcast to all the user resources of the updated roster item // Brodcast to all the user resources of the updated roster item
broadcast(item); broadcast(item);
// Presences of shared users are of type BOTH so probe for presences // Probe the presence of the new group user
presenceManager.probePresence(username, item.getJid()); if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) {
presenceManager.probePresence(username, item.getJid());
}
} }
/** /**
......
...@@ -209,13 +209,7 @@ public class RosterItem implements Cacheable { ...@@ -209,13 +209,7 @@ public class RosterItem implements Cacheable {
* @return The subscription status of the item * @return The subscription status of the item
*/ */
public SubType getSubStatus() { public SubType getSubStatus() {
if (isShared()) { return subStatus;
// Redefine the sub status since the item belongs to a shared group
return SUB_BOTH;
}
else {
return subStatus;
}
} }
/** /**
......
...@@ -38,8 +38,10 @@ errorPage="error.jsp"%> ...@@ -38,8 +38,10 @@ errorPage="error.jsp"%>
boolean cancel = request.getParameter("cancel") != null; boolean cancel = request.getParameter("cancel") != null;
String name = ParamUtils.getParameter(request, "name"); String name = ParamUtils.getParameter(request, "name");
String description = ParamUtils.getParameter(request, "description"); String description = ParamUtils.getParameter(request, "description");
boolean showInRoster = ParamUtils.getBooleanParameter(request, "show", false); String showInRosterType = ParamUtils.getParameter(request, "show");
boolean showInRoster = "onlyGroup".equals(showInRosterType) || "everybody".equals(showInRosterType);
String displayName = ParamUtils.getParameter(request, "display"); String displayName = ParamUtils.getParameter(request, "display");
String groupList = ParamUtils.getParameter(request, "groupList");
String users = ParamUtils.getParameter(request, "users", true); String users = ParamUtils.getParameter(request, "users", true);
// Handle a cancel // Handle a cancel
if (cancel) { if (cancel) {
...@@ -63,12 +65,14 @@ errorPage="error.jsp"%> ...@@ -63,12 +65,14 @@ errorPage="error.jsp"%>
newGroup.setDescription(description); newGroup.setDescription(description);
} }
if (showInRoster) { if (showInRoster) {
newGroup.getProperties().put("showInRoster", "true"); newGroup.getProperties().put("sharedRoster.showInRoster", showInRosterType);
newGroup.getProperties().put("displayName", displayName); newGroup.getProperties().put("sharedRoster.displayName", displayName);
newGroup.getProperties().put("sharedRoster.groupList", groupList == null ? "" : groupList);
} }
else { else {
newGroup.getProperties().put("showInRoster", "false"); newGroup.getProperties().put("sharedRoster.showInRoster", "nobody");
newGroup.getProperties().put("displayName", ""); newGroup.getProperties().put("sharedRoster.displayName", "");
newGroup.getProperties().put("sharedRoster.groupList", "");
} }
if(users.length() > 0){ if(users.length() > 0){
...@@ -115,7 +119,18 @@ errorPage="error.jsp"%> ...@@ -115,7 +119,18 @@ errorPage="error.jsp"%>
<!-- <!--
function refreshDisplayName(showCheck) function refreshDisplayName(showCheck)
{ {
document.forms.f.display.disabled=!showCheck.checked; if ("onlyGroup" == showCheck.value) {
document.forms.f.newDisplay.disabled=false;
document.forms.f.newGroupList.disabled=false;
}
else if ("everybody" == showCheck.value) {
document.forms.f.newDisplay.disabled=false;
document.forms.f.newGroupList.disabled=true;
}
else {
document.forms.f.newDisplay.disabled=true;
document.forms.f.newGroupList.disabled=true;
}
} }
function setDisplayName() function setDisplayName()
{ {
...@@ -206,10 +221,16 @@ errorPage="error.jsp"%> ...@@ -206,10 +221,16 @@ errorPage="error.jsp"%>
<tr><td height="15" colspan="3"><img src="images/blank.gif"></td> <tr><td height="15" colspan="3"><img src="images/blank.gif"></td>
<tr> <tr>
<td width="1%" nowrap> <td width="1%" nowrap>
<label for="gshow">Show group in group members' rosters:</label> <label for="gshow">Show group in rosters for:</label>
</td> </td>
<td width="99%"> <td width="99%">
<input type="checkbox" name="show" value="true" id="gshow" onclick="refreshDisplayName(this)"/> <label for="onlyGroup">Only group users</label>
<input type="radio" name="show" id="onlyGroup" value="onlyGroup" onclick="refreshDisplayName(this)"/>&nbsp;&nbsp;
<label for="everybody">Everybody</label>
<input type="radio" name="show" id="everybody" value="everybody" onclick="refreshDisplayName(this)"/>&nbsp;&nbsp;
<label for="nobody">Nobody</label>
<input type="radio" name="show" id="nobody" value="nobody" checked onclick="refreshDisplayName(this)"/>
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -227,6 +248,14 @@ errorPage="error.jsp"%> ...@@ -227,6 +248,14 @@ errorPage="error.jsp"%>
%> %>
</td> </td>
</tr> </tr>
<tr>
<td nowrap width="1%">
<label for="gGroupList">Viewable by groups:</label>
</td>
<td width="99%">
<textarea name="groupList" cols="30" rows="2" id="gGroupList"><%= ((groupList != null) ? groupList : "") %></textarea>
</td>
</tr>
</table> </table>
<br> <br>
<span class="jive-description"> * Required fields </span> <span class="jive-description"> * Required fields </span>
......
...@@ -31,8 +31,10 @@ import="java.text.DateFormat, ...@@ -31,8 +31,10 @@ import="java.text.DateFormat,
boolean edit = ParamUtils.getBooleanParameter(request, "edit", false); boolean edit = ParamUtils.getBooleanParameter(request, "edit", false);
String newName = ParamUtils.getParameter(request, "newName"); String newName = ParamUtils.getParameter(request, "newName");
String newDescription = ParamUtils.getParameter(request, "newDescription"); String newDescription = ParamUtils.getParameter(request, "newDescription");
boolean newShowInRoster = ParamUtils.getBooleanParameter(request, "newShow", false); String newShowInRosterType = ParamUtils.getParameter(request, "newShow");
boolean newShowInRoster = "onlyGroup".equals(newShowInRosterType) || "everybody".equals(newShowInRosterType);
String newDisplayName = ParamUtils.getParameter(request, "newDisplay"); String newDisplayName = ParamUtils.getParameter(request, "newDisplay");
String newGroupList = ParamUtils.getParameter(request, "newGroupList");
boolean groupInfoChanged = ParamUtils.getBooleanParameter(request, "groupChanged", false); boolean groupInfoChanged = ParamUtils.getBooleanParameter(request, "groupChanged", false);
Group group = groupManager.getGroup(groupName); Group group = groupManager.getGroup(groupName);
...@@ -48,12 +50,14 @@ import="java.text.DateFormat, ...@@ -48,12 +50,14 @@ import="java.text.DateFormat,
group.setName(newName); group.setName(newName);
group.setDescription(newDescription); group.setDescription(newDescription);
if (newShowInRoster) { if (newShowInRoster) {
group.getProperties().put("showInRoster", "true"); group.getProperties().put("sharedRoster.showInRoster", newShowInRosterType);
group.getProperties().put("displayName", newDisplayName); group.getProperties().put("sharedRoster.displayName", newDisplayName);
group.getProperties().put("sharedRoster.groupList", newGroupList == null ? "" : newGroupList);
} }
else { else {
group.getProperties().put("showInRoster", "false"); group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("displayName", ""); group.getProperties().put("sharedRoster.displayName", "");
group.getProperties().put("sharedRoster.groupList", "");
} }
groupName = newName; groupName = newName;
groupInfoChanged = true; groupInfoChanged = true;
...@@ -169,7 +173,18 @@ import="java.text.DateFormat, ...@@ -169,7 +173,18 @@ import="java.text.DateFormat,
<!-- <!--
function refreshDisplayName(showCheck) function refreshDisplayName(showCheck)
{ {
document.forms.ff.newDisplay.disabled=!showCheck.checked; if ("onlyGroup" == showCheck.value) {
document.forms.ff.newDisplay.disabled=false;
document.forms.ff.newGroupList.disabled=false;
}
else if ("everybody" == showCheck.value) {
document.forms.ff.newDisplay.disabled=false;
document.forms.ff.newGroupList.disabled=true;
}
else {
document.forms.ff.newDisplay.disabled=true;
document.forms.ff.newGroupList.disabled=true;
}
} }
//--> //-->
</script> </script>
...@@ -258,7 +273,7 @@ import="java.text.DateFormat, ...@@ -258,7 +273,7 @@ import="java.text.DateFormat,
<% } else { %> <% } else { %>
<td> <td>
<input type="text" name="newDescription" value="<%= group.getDescription() != null ? group.getDescription() : "" %>"> <textarea name="newDescription" cols="40" rows="4"><%= group.getDescription() != null ? group.getDescription() : "" %></textarea>
</td> </td>
<% } %> <% } %>
...@@ -266,17 +281,36 @@ import="java.text.DateFormat, ...@@ -266,17 +281,36 @@ import="java.text.DateFormat,
<tr><td height="15" colspan="3"><img src="images/blank.gif"></td> <tr><td height="15" colspan="3"><img src="images/blank.gif"></td>
<tr> <tr>
<td width="1%" nowrap> <td width="1%" nowrap>
Show group in group members' rosters: Show group in rosters for:
</td> </td>
<% boolean showInRoster = "true".equals(group.getProperties().get("showInRoster")) || errors.get("display") != null; <% boolean showInRoster = webManager.getRosterManager().isSharedGroup(group) || errors.get("display") != null;
if(!edit) { %> if(!edit) { %>
<td colspan="2"> <td colspan="2">
<%= (showInRoster ? "Enabled" : "Disabled") %> <% if ("onlyGroup".equals(group.getProperties().get("sharedRoster.showInRoster"))) {
out.print("Only group users");
}
else if ("everybody".equals(group.getProperties().get("sharedRoster.showInRoster"))) {
out.print("Everybody");
}
else {
out.print("Nobody");
}
%>
</td> </td>
<% } else { %> <% } else {
String showInRosterType = group.getProperties().get("sharedRoster.showInRoster");
if (errors.get("display") != null && newShowInRosterType != null) {
showInRosterType = newShowInRosterType;
}
%>
<td> <td>
<input type="checkbox" name="newShow" value="true" <%= (showInRoster ? "checked" : "") %> onclick="refreshDisplayName(this)"/> <label for="onlyGroup">Only group users</label>
<input type="radio" name="newShow" id="onlyGroup" value="onlyGroup" <%= ("onlyGroup".equals(showInRosterType) ? "checked" : "") %> onclick="refreshDisplayName(this)"/>&nbsp;&nbsp;
<label for="everybody">Everybody</label>
<input type="radio" name="newShow" id="everybody" value="everybody" <%= ("everybody".equals(showInRosterType) ? "checked" : "") %> onclick="refreshDisplayName(this)"/>&nbsp;&nbsp;
<label for="nobody">Nobody</label>
<input type="radio" name="newShow" id="nobody" value="nobody" <%= (!"onlyGroup".equals(showInRosterType) && !"everybody".equals(showInRosterType) ? "checked" : "") %> onclick="refreshDisplayName(this)"/>
</td> </td>
<% } %> <% } %>
...@@ -285,7 +319,7 @@ import="java.text.DateFormat, ...@@ -285,7 +319,7 @@ import="java.text.DateFormat,
<td width="1%" nowrap> <td width="1%" nowrap>
Display name in roster: Display name in roster:
</td> </td>
<% String displayName = (group.getProperties().get("displayName") == null ? "" : group.getProperties().get("displayName")); <% String displayName = (group.getProperties().get("sharedRoster.displayName") == null ? "" : group.getProperties().get("sharedRoster.displayName"));
if(!edit) { %> if(!edit) { %>
<td colspan="2"> <td colspan="2">
<%= displayName %> <%= displayName %>
...@@ -305,6 +339,31 @@ import="java.text.DateFormat, ...@@ -305,6 +339,31 @@ import="java.text.DateFormat,
<% } %> <% } %>
</tr> </tr>
<tr>
<td width="1%" nowrap>
Viewable by groups:
</td>
<% boolean enableGroupList = "onlyGroup".equals(group.getProperties().get("sharedRoster.showInRoster")) || errors.get("display") != null;
String groupList = (group.getProperties().get("sharedRoster.groupList") == null ? "" : group.getProperties().get("sharedRoster.groupList"));
if(!edit) { %>
<td colspan="2">
<%= groupList %>
</td>
<% } else { %>
<td>
<textarea name="newGroupList" cols="40" rows="2" <%= enableGroupList ? "" : "disabled"%>><%= groupList %></textarea>
<%
if (errors.get("groupList") != null) {
%>
<span class="jive-error-text"> Please enter existing group names separated by commas. </span>
<%
}
%>
</td>
<% } %>
</tr>
<% if(edit) { %> <% if(edit) { %>
<tr> <tr>
<td colspan="3"> <td colspan="3">
......
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