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