private void calculateNumberOfChats(AgentRoster agentRoster) { int counter = 0; // TODO: CHECK FASTPATH //for (String agent : agentRoster.getAgents()) { for (Iterator it = agentRoster.getAgents().iterator(); it.hasNext();) { String agent = (String)it.next(); Presence presence = agentRoster.getPresence(agent); if (presence.isAvailable()) { AgentStatus agentStatus = (AgentStatus)presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup"); if (agentStatus != null) { counter += agentStatus.getCurrentChats().size(); } } } FastpathPlugin.getUI().setTitleForComponent(FpRes.getString("message.current.chats", counter), this); }
/** * Sets the agent's current status with the workgroup. The presence mode affects how offers * are routed to the agent. The possible presence modes with their meanings are as follows:<ul> * <p/> * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats * (equivalent to Presence.Mode.CHAT). * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed. * However, special case, or extreme urgency chats may still be offered to the agent. * <li>Presence.Mode.AWAY -- the agent is not available and should not * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul> * <p/> * The max chats value is the maximum number of chats the agent is willing to have routed to * them at once. Some servers may be configured to only accept max chat values in a certain * range; for example, between two and five. In that case, the maxChats value the agent sends * may be adjusted by the server to a value within that range. * * @param presenceMode the presence mode of the agent. * @param maxChats the maximum number of chats the agent is willing to accept. * @param status sets the status message of the presence update. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws IllegalStateException if the agent is not online with the workgroup. */ public void setStatus(Presence.Mode presenceMode, int maxChats, String status) throws NoResponseException, XMPPErrorException, NotConnectedException { if (!online) { throw new IllegalStateException("Cannot set status when the agent is not online."); } if (presenceMode == null) { presenceMode = Presence.Mode.available; } this.presenceMode = presenceMode; this.maxChats = maxChats; Presence presence = new Presence(Presence.Type.available); presence.setMode(presenceMode); presence.setTo(this.getWorkgroupJID()); if (status != null) { presence.setStatus(status); } // Send information about max chats and current chats as a packet extension. DefaultExtensionElement agentStatus = new DefaultExtensionElement(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE); agentStatus.setValue("max-chats", "" + maxChats); presence.addExtension(agentStatus); presence.addExtension(new MetaData(this.metaData)); PacketCollector collector = this.connection.createPacketCollectorAndSend(new AndFilter( new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence); collector.nextResultOrThrow(); }
private boolean newListHasSession(String sessionID, List chatList) { // Add new ones. Iterator iter = chatList.iterator(); while (iter.hasNext()) { AgentStatus.ChatInfo chatInfo = (AgentStatus.ChatInfo)iter.next(); String session = chatInfo.getSessionID(); if (session.equalsIgnoreCase(sessionID)) { return true; } } return false; }
private String buildTooltip(Presence presence) { if (!presence.isAvailable()) { return FpRes.getString("message.user.not.logged.in"); } AgentStatus agentStatus = (AgentStatus)presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup"); List<AgentStatus.ChatInfo> list = agentStatus.getCurrentChats(); // Add new ones. Iterator<AgentStatus.ChatInfo> iter = list.iterator(); StringBuffer buf = new StringBuffer(); buf.append("<html>"); buf.append("<body>"); buf.append("<table>"); while (iter.hasNext()) { AgentStatus.ChatInfo chatInfo = iter.next(); Date startDate = chatInfo.getDate(); String username = chatInfo.getUserID(); String nickname = chatInfo.getUsername(); if (!ModelUtil.hasLength(nickname)) { nickname = FpRes.getString("message.not.specified"); } String question = chatInfo.getQuestion(); if (!ModelUtil.hasLength(question)) { question = "No question asked"; } String email = chatInfo.getEmail(); if (!ModelUtil.hasLength(email)) { email = FpRes.getString("message.not.specified"); } long startTime = startDate.getTime(); long rightNow = System.currentTimeMillis(); long totalTime = rightNow - startTime; String durationTime = ModelUtil.getTimeFromLong(totalTime); buf.append("<tr><td><b><u>Chatting with ").append(nickname).append("</u></b></td></tr>"); buf.append("<tr><td>Email: ").append(email).append("</td></tr>"); buf.append("<tr><td>Question: ").append(question).append("</td></tr>"); buf.append("<tr><td>Chat Duration: ").append(durationTime).append("</td></tr>"); buf.append("<tr><td><br></td></tr>"); } if (list.size() == 0) { buf.append(FpRes.getString("message.agent.is.not.in.chat")); } buf.append("</table>"); buf.append("</body>"); buf.append("</html>"); return buf.toString(); }