Commit 30973cea authored by Matt Tucker's avatar Matt Tucker Committed by matt

UI updates.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@345 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9e446f66
...@@ -65,8 +65,6 @@ public interface Presence extends XMPPPacket { ...@@ -65,8 +65,6 @@ public interface Presence extends XMPPPacket {
public static final int STATUS_IDLE = 1; public static final int STATUS_IDLE = 1;
public static final int STATUS_INVISIBLE = 2;
public static final int STATUS_OFFLINE = 4; public static final int STATUS_OFFLINE = 4;
public static final int STATUS_PROBE = -1; public static final int STATUS_PROBE = -1;
...@@ -91,10 +89,6 @@ public interface Presence extends XMPPPacket { ...@@ -91,10 +89,6 @@ public interface Presence extends XMPPPacket {
* Do not disturb show state * Do not disturb show state
*/ */
public static final int SHOW_DND = 104; public static final int SHOW_DND = 104;
/**
* Invisible show state (user not shown)
*/
public static final int SHOW_INVISIBLE = 110;
/** /**
* The online/offline status of the user. Being available indicates that the node can be * The online/offline status of the user. Being available indicates that the node can be
......
...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger; ...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.User; import org.jivesoftware.messenger.user.User;
import java.util.Iterator;
import java.util.Collection; import java.util.Collection;
/** /**
...@@ -39,10 +38,28 @@ public interface PresenceManager { ...@@ -39,10 +38,28 @@ public interface PresenceManager {
/** /**
* <p>Returns the availability of the user.<p> * <p>Returns the availability of the user.<p>
* *
* @param user The user who's availability is in question * @param user the user who's availability is in question
* @return True if the user as available for messaging (1 or more available sessions) * @return true if the user as available for messaging (1 or more available sessions)
*/ */
public boolean isAvailable(User user) throws UnauthorizedException; public boolean isAvailable(User user);
/**
* Returns the user's current presence, or <tt>null</tt> if the user is unavailable.
* If the user is connected with more than one session, the user's "most available"
* presence status is returned.
*
* @param user the user.
* @return the user's current presence.
*/
public Presence getPresence(User user);
/**
* Returns all presences for the user, or <tt>null</tt> if the user is unavailable.
*
* @param user the user.
* @return the Presence packets for all the users's connected sessions.
*/
public Collection<Presence> getPresences(User user);
/** /**
* Returns the number of guests who are currently online. Guests with a * Returns the number of guests who are currently online. Guests with a
......
...@@ -13,6 +13,7 @@ package org.jivesoftware.messenger; ...@@ -13,6 +13,7 @@ package org.jivesoftware.messenger;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Collection;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
/** /**
...@@ -111,7 +112,7 @@ public interface SessionManager { ...@@ -111,7 +112,7 @@ public interface SessionManager {
* @return An iterator over the sessions (never null) * @return An iterator over the sessions (never null)
* @throws UnauthorizedException If caller doesn't have permission to access this method * @throws UnauthorizedException If caller doesn't have permission to access this method
*/ */
public Iterator getSessions(String username) throws UnauthorizedException; public Collection<Session> getSessions(String username) throws UnauthorizedException;
/** /**
* <p>Obtain a count of the number of sessions on the server, including unauthenticated * <p>Obtain a count of the number of sessions on the server, including unauthenticated
......
...@@ -652,19 +652,15 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -652,19 +652,15 @@ public class MUCRoomImpl implements MUCRoom {
Presence presence = new PresenceImpl(); Presence presence = new PresenceImpl();
presence.setSender(role.getRoleAddress()); presence.setSender(role.getRoleAddress());
switch (presenceStatus) { switch (presenceStatus) {
case Presence.STATUS_INVISIBLE: case Presence.STATUS_ONLINE:
presence.setAvailable(true); presence.setAvailable(true);
presence.setVisible(false); presence.setVisible(true);
break; break;
case Presence.STATUS_ONLINE: case Presence.STATUS_OFFLINE:
presence.setAvailable(true); presence.setAvailable(false);
presence.setVisible(true); presence.setVisible(false);
break; break;
case Presence.STATUS_OFFLINE: default:
presence.setAvailable(false);
presence.setVisible(false);
break;
default:
} }
return presence; return presence;
} }
......
...@@ -223,11 +223,6 @@ public class PresenceImpl extends AbstractPacket implements Presence, Cacheable ...@@ -223,11 +223,6 @@ public class PresenceImpl extends AbstractPacket implements Presence, Cacheable
xmlSerializer.writeCharacters("dnd"); xmlSerializer.writeCharacters("dnd");
xmlSerializer.writeEndElement(); xmlSerializer.writeEndElement();
break; break;
case Presence.SHOW_INVISIBLE:
xmlSerializer.writeStartElement("jabber:client", "show");
xmlSerializer.writeCharacters("invisible");
xmlSerializer.writeEndElement();
break;
} }
if (status != null && status.length() > 0) { if (status != null && status.length() > 0) {
xmlSerializer.writeStartElement("jabber:client", "status"); xmlSerializer.writeStartElement("jabber:client", "status");
......
...@@ -66,10 +66,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -66,10 +66,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
foreignUserCache = new Cache("Foreign Users", foreignCacheSize, HOUR); foreignUserCache = new Cache("Foreign Users", foreignCacheSize, HOUR);
} }
public boolean isAvailable(User user) throws UnauthorizedException {
return sessionManager.getSessionCount(user.getUsername()) > 0;
}
public int getOnlineGuestCount() { public int getOnlineGuestCount() {
int count = 0; int count = 0;
for (Presence presence : onlineGuests.values()) { for (Presence presence : onlineGuests.values()) {
...@@ -225,14 +221,11 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -225,14 +221,11 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public void setOffline(XMPPAddress jid) throws UnauthorizedException { public void setOffline(XMPPAddress jid) throws UnauthorizedException {
} }
public boolean isOnline(User user) { public boolean isAvailable(User user) {
if (user == null) { try {
return false; return sessionManager.getSessionCount(user.getUsername()) > 0;
}
Presence presence = (Presence)onlineUsers.get(user.getUsername());
if (presence != null) {
return presence.isAvailable();
} }
catch (UnauthorizedException ue) { }
return false; return false;
} }
...@@ -240,15 +233,33 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -240,15 +233,33 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
if (user == null) { if (user == null) {
return null; return null;
} }
// try getting the presence obj from the online user cache: Presence presence = null;
Presence userPresence = (Presence)onlineUsers.get(user.getUsername()); try {
if (userPresence != null) { for (Session session : sessionManager.getSessions(user.getUsername())) {
return userPresence; if (presence == null) {
presence = session.getPresence();
}
else if (presence.getShow() > session.getPresence().getShow()) {
presence = session.getPresence();
}
}
} }
else { catch (UnauthorizedException ue) { }
// Load up the presence from the db return presence;
return new PresenceImpl(user, null); }
public Collection<Presence> getPresences(User user) {
if (user == null) {
return null;
}
List<Presence> presences = new ArrayList<Presence>();
try {
for (Session session : sessionManager.getSessions(user.getUsername())) {
presences.add(session.getPresence());
}
} }
catch (UnauthorizedException ue) { }
return Collections.unmodifiableCollection(presences);
} }
public Presence getPresence(String presenceID) { public Presence getPresence(String presenceID) {
...@@ -280,10 +291,11 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -280,10 +291,11 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
Component component = getPresenceComponent(probee); Component component = getPresenceComponent(probee);
if (server.isLocal(probee)) { if (server.isLocal(probee)) {
if (probee.getNamePrep() != null && !"".equals(probee.getNamePrep())) { if (probee.getNamePrep() != null && !"".equals(probee.getNamePrep())) {
Iterator sessionIter = sessionManager.getSessions(probee.getNamePrep()); Collection<Session> sessions =
while (sessionIter.hasNext()) { sessionManager.getSessions(probee.getNamePrep());
Session session = (Session)sessionIter.next(); for (Session session : sessions) {
Presence presencePacket = (Presence)session.getPresence().createDeepCopy(); Presence presencePacket =
(Presence)session.getPresence().createDeepCopy();
presencePacket.setSender(session.getAddress()); presencePacket.setSender(session.getAddress());
try { try {
sessionManager.userBroadcast(prober, presencePacket); sessionManager.userBroadcast(prober, presencePacket);
...@@ -327,10 +339,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -327,10 +339,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public void probePresence(XMPPAddress prober, XMPPAddress probee) { public void probePresence(XMPPAddress prober, XMPPAddress probee) {
try { try {
if (server.isLocal(probee)) { if (server.isLocal(probee)) {
Iterator sessionIter = Collection<Session> sessions =
sessionManager.getSessions(probee.getName().toLowerCase()); sessionManager.getSessions(probee.getName().toLowerCase());
while (sessionIter.hasNext()) { for (Session session : sessions) {
Session session = (Session)sessionIter.next();
Presence presencePacket = Presence presencePacket =
(Presence)session.getPresence().createDeepCopy(); (Presence)session.getPresence().createDeepCopy();
presencePacket.setSender(session.getAddress()); presencePacket.setSender(session.getAddress());
......
...@@ -38,10 +38,18 @@ public class PresenceManagerProxy implements PresenceManager { ...@@ -38,10 +38,18 @@ public class PresenceManagerProxy implements PresenceManager {
this.permissions = permissions; this.permissions = permissions;
} }
public boolean isAvailable(User user) throws UnauthorizedException { public boolean isAvailable(User user) {
return manager.isAvailable(user); return manager.isAvailable(user);
} }
public Presence getPresence(User user) {
return manager.getPresence(user);
}
public Collection<Presence> getPresences(User user) {
return manager.getPresences(user);
}
public int getOnlineGuestCount() { public int getOnlineGuestCount() {
return manager.getOnlineGuestCount(); return manager.getOnlineGuestCount();
} }
......
...@@ -22,6 +22,7 @@ import org.jivesoftware.messenger.user.UserNotFoundException; ...@@ -22,6 +22,7 @@ import org.jivesoftware.messenger.user.UserNotFoundException;
import java.util.*; import java.util.*;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
/** /**
...@@ -79,7 +80,7 @@ public class SessionManagerImpl extends BasicModule implements SessionManager, ...@@ -79,7 +80,7 @@ public class SessionManagerImpl extends BasicModule implements SessionManager,
* Map of priority ordered SessionMap objects with username (toLowerCase) as key. * Map of priority ordered SessionMap objects with username (toLowerCase) as key.
* The map and its contents should NOT be persisted to disk. * The map and its contents should NOT be persisted to disk.
*/ */
private HashMap sessions = new HashMap(); private Map<String, SessionMap> sessions = new ConcurrentHashMap<String, SessionMap>();
/** /**
* <p>Session manager must maintain the routing table as sessions are added and * <p>Session manager must maintain the routing table as sessions are added and
...@@ -624,9 +625,9 @@ public class SessionManagerImpl extends BasicModule implements SessionManager, ...@@ -624,9 +625,9 @@ public class SessionManagerImpl extends BasicModule implements SessionManager,
try { try {
Iterator users = getSessionUsers(); Iterator users = getSessionUsers();
while (users.hasNext()) { while (users.hasNext()) {
Iterator sessionItr = getSessions((String)users.next()); Collection<Session> usrSessions = getSessions((String)users.next());
while (sessionItr.hasNext()) { for (Session session : usrSessions) {
sessions.add(sessionItr.next()); sessions.add(session);
} }
} }
} }
...@@ -656,13 +657,12 @@ public class SessionManagerImpl extends BasicModule implements SessionManager, ...@@ -656,13 +657,12 @@ public class SessionManagerImpl extends BasicModule implements SessionManager,
return Arrays.asList(anonymousSessions.values().toArray()).iterator(); return Arrays.asList(anonymousSessions.values().toArray()).iterator();
} }
public Iterator getSessions(String username) { public Collection<Session> getSessions(String username) {
List<Session> sessionList = new ArrayList<Session>();
LinkedList sessionList = new LinkedList();
if (username != null) { if (username != null) {
copyUserSessions(username, sessionList); copyUserSessions(username, sessionList);
} }
return sessionList.iterator(); return sessionList;
} }
public int getTotalSessionCount() throws UnauthorizedException { public int getTotalSessionCount() throws UnauthorizedException {
......
...@@ -16,6 +16,7 @@ import org.jivesoftware.messenger.auth.AuthToken; ...@@ -16,6 +16,7 @@ import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions; import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Collection;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
/** /**
...@@ -96,7 +97,7 @@ public class SessionManagerProxy implements SessionManager { ...@@ -96,7 +97,7 @@ public class SessionManagerProxy implements SessionManager {
} }
} }
public Iterator getSessions(String username) throws UnauthorizedException { public Collection<Session> getSessions(String username) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) { if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
return sessionManager.getSessions(username); return sessionManager.getSessions(username);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
--%> --%>
<%@ taglib uri="core" prefix="c"%> <%@ taglib uri="core" prefix="c"%>
<%@ page import="org.jivesoftware.util.*, <%@ page import="org.jivesoftware.util.*,
java.util.Iterator, java.util.*,
org.jivesoftware.messenger.*, org.jivesoftware.messenger.*,
java.text.DateFormat, java.text.DateFormat,
java.text.NumberFormat, java.text.NumberFormat,
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
} }
// See if there are multiple sessions for this user: // See if there are multiple sessions for this user:
Iterator sessions = null; Collection<Session> sessions = null;
int sessionCount = sessionManager.getSessionCount(address.getName()); int sessionCount = sessionManager.getSessionCount(address.getName());
if (!isAnonymous && sessionCount > 1) { if (!isAnonymous && sessionCount > 1) {
sessions = sessionManager.getSessions(address.getName()); sessions = sessionManager.getSessions(address.getName());
...@@ -258,8 +258,7 @@ user <b><%= address.getName() %></b> has multiple sessions open, they will appea ...@@ -258,8 +258,7 @@ user <b><%= address.getName() %></b> has multiple sessions open, they will appea
<% int count = 0; <% int count = 0;
String linkURL = "session-details.jsp"; String linkURL = "session-details.jsp";
while (sessions.hasNext()) { for (Session sess : sessions) {
Session sess = (Session) sessions.next();
count++; count++;
boolean current = sess.getAddress().equals(address); boolean current = sess.getAddress().equals(address);
%> %>
......
...@@ -75,15 +75,7 @@ ...@@ -75,15 +75,7 @@
<% } %> <% } %>
<%
String maxSession = "Unlimited";
int maxSessions = -1;
if(maxSessions != -1){
maxSession = ""+maxSessions;
}
%>
Active Sessions: <b><%= sessionCount %></b>, Active Sessions: <b><%= sessionCount %></b>,
Maximum Allowable Sessions: <%= maxSession %>
<% if (numPages > 1) { %> <% if (numPages > 1) { %>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<%@ page import="org.jivesoftware.util.*, <%@ page import="org.jivesoftware.util.*,
org.jivesoftware.messenger.user.*, org.jivesoftware.messenger.user.*,
java.text.DateFormat, java.text.DateFormat,
java.util.Iterator, java.util.*,
org.jivesoftware.admin.*, org.jivesoftware.admin.*,
org.jivesoftware.messenger.*" org.jivesoftware.messenger.*"
%> %>
...@@ -101,26 +101,37 @@ send the user a message (if they're online) or delete the user. ...@@ -101,26 +101,37 @@ send the user a message (if they're online) or delete the user.
<tr class="jive-even"> <tr class="jive-even">
<td wrap width="1%"> <td wrap width="1%">
Online Status: Status:
</td> </td>
<td> <td valign="middle">
<% if (admin.getPresenceManager().isAvailable(user)) { <% if (presenceManager.isAvailable(user)) {
// Get the user's session (or the first one available if there are multiple) Presence presence = presenceManager.getPresence(user);
Iterator sessions = admin.getSessionManager().getSessions(user.getUsername()); %>
// Should be at least one session, so grab first one. Just need to pass in one <% if (presence.getShow() == Presence.SHOW_NONE) { %>
// of the user's sessions to the session details page - that page will display <img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available">
// all that exist. Available
Session sess = (Session)sessions.next(); <% } %>
%> <% if (presence.getShow() == Presence.SHOW_CHAT) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available to Chat">
<img src="images/online.gif" width="13" height="17" border="0" hspace="3" Available to Chat
title="User is online."> <% } %>
(Online - see <a href="session-details.jsp?jid=<%= sess.getAddress().toString() %>">user session(s)</a>.) <% if (presence.getShow() == Presence.SHOW_AWAY) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Away">
Away
<% } %>
<% if (presence.getShow() == Presence.SHOW_XA) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Extended Away">
Extended Away
<% } %>
<% if (presence.getShow() == Presence.SHOW_DND) { %>
<img src="images/user-red-16x16.gif" width="16" height="16" border="0" alt="Do not Disturb">
Do not Disturb
<% } %>
<% } else { %> <% } else { %>
<img src="images/offline.gif" width="8" height="17" border="0" hspace="3" <img src="images/user-clear-16x16.gif" width="16" height="16" border="0" alt="Offline">
title="User is offline.">
(Offline) (Offline)
<% } %> <% } %>
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
org.jivesoftware.messenger.user.UserManager, org.jivesoftware.messenger.user.UserManager,
java.text.DateFormat, java.text.DateFormat,
org.jivesoftware.admin.*, org.jivesoftware.admin.*,
org.jivesoftware.messenger.PresenceManager" org.jivesoftware.messenger.PresenceManager,
org.jivesoftware.messenger.Presence"
%> %>
<%-- Define Administration Bean --%> <%-- Define Administration Bean --%>
...@@ -62,7 +63,7 @@ Total Users: <%= webManager.getUserManager().getUserCount() %>, ...@@ -62,7 +63,7 @@ Total Users: <%= webManager.getUserManager().getUserCount() %>,
Showing <%= (start+1) %>-<%= (start+range) %>, Showing <%= (start+1) %>-<%= (start+range) %>,
<% } %> <% } %>
Sorted by User ID Sorted by Username
</p> </p>
<% if (numPages > 1) { %> <% if (numPages > 1) { %>
...@@ -85,7 +86,6 @@ Sorted by User ID ...@@ -85,7 +86,6 @@ Sorted by User ID
<% } %> <% } %>
<table cellpadding="3" cellspacing="0" border="0" width="600"> <table cellpadding="3" cellspacing="0" border="0" width="600">
<tr class="tableHeader"><td colspan="7" align="left">List Of Users</td></tr>
</table> </table>
<table class="jive-table" cellpadding="3" cellspacing="0" border="0" width="600"> <table class="jive-table" cellpadding="3" cellspacing="0" border="0" width="600">
<tr > <tr >
...@@ -114,18 +114,33 @@ Sorted by User ID ...@@ -114,18 +114,33 @@ Sorted by User ID
User user = (User)users.next(); User user = (User)users.next();
i++; i++;
%> %>
<tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>"> <tr class="jive-<%= (((i%2)==0) ? "odd" : "odd") %>">
<td width="1%"> <td width="1%">
<%= i %> <%= i %>
</td> </td>
<td width="1%" align="center"> <td width="1%" align="center" valign="middle">
<% if (presenceManager.isAvailable(user)) { %> <% if (presenceManager.isAvailable(user)) {
Presence presence = presenceManager.getPresence(user);
<img src="images/online.gif" width="13" height="17" border="0"> %>
<% if (presence.getShow() == Presence.SHOW_NONE) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available">
<% } %>
<% if (presence.getShow() == Presence.SHOW_CHAT) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available to Chat">
<% } %>
<% if (presence.getShow() == Presence.SHOW_AWAY) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Away">
<% } %>
<% if (presence.getShow() == Presence.SHOW_XA) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Extended Away">
<% } %>
<% if (presence.getShow() == Presence.SHOW_DND) { %>
<img src="images/user-red-16x16.gif" width="16" height="16" border="0" alt="Do not Disturb">
<% } %>
<% } else { %> <% } else { %>
<img src="images/offline.gif" width="8" height="17" border="0"> <img src="images/user-clear-16x16.gif" width="16" height="16" border="0" alt="Offline">
<% } %> <% } %>
</td> </td>
......
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