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
private void copyUserSessions(List sessions) {
// Get a copy of the sessions from all users
Iterator users = getSessionUsers();
while (users.hasNext()) {
Collection<Session> usrSessions = getSessions((String)users.next());
for (String username : getSessionUsers()) {
Collection<Session> usrSessions = getSessions(username);
for (Session session : usrSessions) {
sessions.add(session);
}
......@@ -759,9 +758,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
public int getSessionCount() {
int sessionCount = 0;
Iterator users = getSessionUsers();
while (users.hasNext()) {
sessionCount += getSessionCount((String)users.next());
for (String username : getSessionUsers()) {
sessionCount += getSessionCount(username);
}
sessionCount += anonymousSessions.size();
return sessionCount;
......@@ -780,8 +778,8 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
return sessionCount;
}
public Iterator getSessionUsers() {
return Arrays.asList(sessions.keySet().toArray()).iterator();
public Collection<String> getSessionUsers() {
return Collections.unmodifiableCollection(sessions.keySet());
}
/**
......
......@@ -73,13 +73,7 @@ public class Roster implements Cacheable {
Collection<Group> sharedGroups = null;
try {
User rosterUser = UserManager.getInstance().getUser(getUsername());
sharedGroups = GroupManager.getInstance().getGroups(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();
}
}
sharedGroups = XMPPServer.getInstance().getRosterManager().getSharedGroups(rosterUser);
}
catch (UserNotFoundException e) {
sharedGroups = new ArrayList<Group>();
......@@ -95,22 +89,32 @@ public class Roster implements Cacheable {
for (Group group : sharedGroups) {
if (group.isUser(item.getJid().getNode())) {
// 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);
}
// 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()) {
try {
RosterItem.SubType type = RosterItem.SUB_TO;
User user = UserManager.getInstance().getUser(jid.getNode());
String nickname = "".equals(user.getName()) ? jid.getNode() : user.getName();
RosterItem item = new RosterItem(jid, RosterItem.SUB_BOTH, RosterItem.ASK_NONE,
RosterItem.RECV_NONE, nickname , null);
for (String group : sharedUsers.get(jid)) {
item.addSharedGroup(group);
if (sharedUsers.get(jid).isEmpty()) {
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);
}
catch (UserNotFoundException e) {
......@@ -231,7 +235,7 @@ public class Roster implements Cacheable {
Collection<Group> sharedGroups = GroupManager.getInstance().getGroups();
for (String group : groups) {
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");
}
}
......@@ -400,26 +404,29 @@ public class Roster implements Cacheable {
* @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<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
// 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) {
// Get all the group users
Collection<String> users = new ArrayList<String>(group.getMembers());
users.addAll(group.getAdmins());
// Get all the users that can have this group in their rosters
Collection<String> users = XMPPServer.getInstance().getRosterManager().getRelatedUsers(group, false);
// 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
// (since we have already added the user to the answer)
JID jid = XMPPServer.getInstance().createJID(groupUser, null);
if (!isRosterItem(jid) && !getUsername().equals(groupUser)) {
List<String> groups = sharedGroupUsers.get(jid);
JID jid = XMPPServer.getInstance().createJID(user, null);
if (!isRosterItem(jid) && !getUsername().equals(user)) {
List<Group> groups = sharedGroupUsers.get(jid);
if (groups == null) {
groups = new ArrayList<String>();
groups = new ArrayList<Group>();
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 {
* group will be added to the shared groups lists. In any case an update broadcast will be sent
* 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.
*/
void addSharedUser(String sharedGroup, String addedUser) {
void addSharedUser(Group group, String addedUser) {
RosterItem item = null;
JID jid = XMPPServer.getInstance().createJID(addedUser, "");
// Get the display name of the group
String groupName = group.getProperties().get("sharedRoster.displayName");
try {
// Get the RosterItem for the *local* user to add
item = getRosterItem(jid);
// Do nothing if the item already includes the shared group
if (item.getSharedGroups().contains(sharedGroup)) {
if (item.getSharedGroups().contains(groupName)) {
return;
}
}
......@@ -501,18 +510,32 @@ public class Roster implements Cacheable {
rosterItems.put(item.getJid().toBareJID(), item);
}
catch (UserNotFoundException ex) {
Log.error("Group (" + sharedGroup + ") includes non-existent username (" +
Log.error("Group (" + groupName + ") includes non-existent username (" +
addedUser +
")");
}
}
// Update the subscription status depending on the group membership of the new user and
// 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(sharedGroup);
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
broadcast(item);
// Presences of shared users are of type BOTH so probe for presences
// Probe the presence of the new group user
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) {
presenceManager.probePresence(username, item.getJid());
}
}
/**
* Update the roster since a group user has been deleted from a shared group. If the RosterItem
......
......@@ -209,14 +209,8 @@ public class RosterItem implements Cacheable {
* @return The subscription status of the item
*/
public SubType getSubStatus() {
if (isShared()) {
// Redefine the sub status since the item belongs to a shared group
return SUB_BOTH;
}
else {
return subStatus;
}
}
/**
* <p>Set the current subscription status of the item.</p>
......
......@@ -38,8 +38,10 @@ errorPage="error.jsp"%>
boolean cancel = request.getParameter("cancel") != null;
String name = ParamUtils.getParameter(request, "name");
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 groupList = ParamUtils.getParameter(request, "groupList");
String users = ParamUtils.getParameter(request, "users", true);
// Handle a cancel
if (cancel) {
......@@ -63,12 +65,14 @@ errorPage="error.jsp"%>
newGroup.setDescription(description);
}
if (showInRoster) {
newGroup.getProperties().put("showInRoster", "true");
newGroup.getProperties().put("displayName", displayName);
newGroup.getProperties().put("sharedRoster.showInRoster", showInRosterType);
newGroup.getProperties().put("sharedRoster.displayName", displayName);
newGroup.getProperties().put("sharedRoster.groupList", groupList == null ? "" : groupList);
}
else {
newGroup.getProperties().put("showInRoster", "false");
newGroup.getProperties().put("displayName", "");
newGroup.getProperties().put("sharedRoster.showInRoster", "nobody");
newGroup.getProperties().put("sharedRoster.displayName", "");
newGroup.getProperties().put("sharedRoster.groupList", "");
}
if(users.length() > 0){
......@@ -115,7 +119,18 @@ errorPage="error.jsp"%>
<!--
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()
{
......@@ -206,10 +221,16 @@ errorPage="error.jsp"%>
<tr><td height="15" colspan="3"><img src="images/blank.gif"></td>
<tr>
<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 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>
</tr>
<tr>
......@@ -227,6 +248,14 @@ errorPage="error.jsp"%>
%>
</td>
</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>
<br>
<span class="jive-description"> * Required fields </span>
......
......@@ -31,8 +31,10 @@ import="java.text.DateFormat,
boolean edit = ParamUtils.getBooleanParameter(request, "edit", false);
String newName = ParamUtils.getParameter(request, "newName");
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 newGroupList = ParamUtils.getParameter(request, "newGroupList");
boolean groupInfoChanged = ParamUtils.getBooleanParameter(request, "groupChanged", false);
Group group = groupManager.getGroup(groupName);
......@@ -48,12 +50,14 @@ import="java.text.DateFormat,
group.setName(newName);
group.setDescription(newDescription);
if (newShowInRoster) {
group.getProperties().put("showInRoster", "true");
group.getProperties().put("displayName", newDisplayName);
group.getProperties().put("sharedRoster.showInRoster", newShowInRosterType);
group.getProperties().put("sharedRoster.displayName", newDisplayName);
group.getProperties().put("sharedRoster.groupList", newGroupList == null ? "" : newGroupList);
}
else {
group.getProperties().put("showInRoster", "false");
group.getProperties().put("displayName", "");
group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("sharedRoster.displayName", "");
group.getProperties().put("sharedRoster.groupList", "");
}
groupName = newName;
groupInfoChanged = true;
......@@ -169,7 +173,18 @@ import="java.text.DateFormat,
<!--
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>
......@@ -258,7 +273,7 @@ import="java.text.DateFormat,
<% } else { %>
<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>
<% } %>
......@@ -266,17 +281,36 @@ import="java.text.DateFormat,
<tr><td height="15" colspan="3"><img src="images/blank.gif"></td>
<tr>
<td width="1%" nowrap>
Show group in group members' rosters:
Show group in rosters for:
</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) { %>
<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>
<% } else { %>
<% } else {
String showInRosterType = group.getProperties().get("sharedRoster.showInRoster");
if (errors.get("display") != null && newShowInRosterType != null) {
showInRosterType = newShowInRosterType;
}
%>
<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>
<% } %>
......@@ -285,7 +319,7 @@ import="java.text.DateFormat,
<td width="1%" nowrap>
Display name in roster:
</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) { %>
<td colspan="2">
<%= displayName %>
......@@ -305,6 +339,31 @@ import="java.text.DateFormat,
<% } %>
</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) { %>
<tr>
<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