Search in sources :

Example 1 with AgentStatus

use of org.jivesoftware.smackx.workgroup.packet.AgentStatus in project Spark by igniterealtime.

the class CurrentActivity method addCurrentChats.

public void addCurrentChats() {
    SwingWorker agentWorker = new SwingWorker() {

        AgentRoster agentRoster;

        Collection agentSet;

        public Object construct() {
            try {
                agentRoster = FastpathPlugin.getAgentSession().getAgentRoster();
            } catch (SmackException.NotConnectedException e) {
                Log.error("Unable to get agent roster.", e);
            }
            agentSet = agentRoster.getAgents();
            return agentSet;
        }

        public void finished() {
            agentRoster.addListener(new AgentRosterListener() {

                public void agentAdded(String jid) {
                }

                public void agentRemoved(String jid) {
                }

                public void presenceChanged(Presence presence) {
                    String agentJID = XmppStringUtils.parseBareJid(presence.getFrom());
                    agentJID = UserManager.unescapeJID(agentJID);
                    AgentStatus agentStatus = (AgentStatus) presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
                    String status = presence.getStatus();
                    if (status == null) {
                        status = "Available";
                    }
                    if (agentStatus != null) {
                        List list = agentStatus.getCurrentChats();
                        // Add new ones.
                        Iterator iter = list.iterator();
                        while (iter.hasNext()) {
                            AgentStatus.ChatInfo chatInfo = (AgentStatus.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");
                            }
                            addAgentChat(agentJID, nickname, email, question, startDate, chatInfo.getSessionID());
                        }
                    }
                }
            });
        }
    };
    agentWorker.start();
}
Also used : AgentRoster(org.jivesoftware.smackx.workgroup.agent.AgentRoster) AgentRosterListener(org.jivesoftware.smackx.workgroup.agent.AgentRosterListener) SmackException(org.jivesoftware.smack.SmackException) Date(java.util.Date) AgentStatus(org.jivesoftware.smackx.workgroup.packet.AgentStatus) Iterator(java.util.Iterator) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Presence(org.jivesoftware.smack.packet.Presence) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List)

Example 2 with AgentStatus

use of org.jivesoftware.smackx.workgroup.packet.AgentStatus in project Spark by igniterealtime.

the class AgentConversations method stateChanged.

public void stateChanged(ChangeEvent e) {
    if (FastpathPlugin.getUI().getMainPanel().getSelectedComponent() == this && list == null) {
        init();
        SwingWorker agentWorker = new SwingWorker() {

            AgentRoster agentRoster;

            Collection agentSet;

            public Object construct() {
                try {
                    agentRoster = FastpathPlugin.getAgentSession().getAgentRoster();
                } catch (SmackException.NotConnectedException e1) {
                    Log.warning("Unable to get agent roster.", e1);
                }
                agentSet = agentRoster.getAgents();
                return agentSet;
            }

            public void finished() {
                agentRoster.addListener(new AgentRosterListener() {

                    public void agentAdded(String jid) {
                    }

                    public void agentRemoved(String jid) {
                    }

                    public void presenceChanged(Presence presence) {
                        String agentJID = XmppStringUtils.parseBareJid(presence.getFrom());
                        AgentStatus agentStatus = (AgentStatus) presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
                        String status = presence.getStatus();
                        if (status == null) {
                            status = "Available";
                        }
                        if (agentStatus != null) {
                            List list = agentStatus.getCurrentChats();
                            removeOldChats(agentJID, list);
                            // Add new ones.
                            Iterator iter = list.iterator();
                            while (iter.hasNext()) {
                                AgentStatus.ChatInfo chatInfo = (AgentStatus.ChatInfo) iter.next();
                                Date startDate = chatInfo.getDate();
                                String username = chatInfo.getUserID();
                                String nickname = chatInfo.getUsername();
                                if (!ModelUtil.hasLength(nickname)) {
                                    nickname = "Not specified";
                                }
                                String question = chatInfo.getQuestion();
                                if (!ModelUtil.hasLength(question)) {
                                    question = "No question asked";
                                }
                                String email = chatInfo.getEmail();
                                if (!ModelUtil.hasLength(email)) {
                                    email = "Not specified";
                                }
                                addAgentChat(agentJID, nickname, email, question, startDate, chatInfo.getSessionID());
                            }
                        }
                        calculateNumberOfChats(agentRoster);
                    }
                });
            }
        };
        agentWorker.start();
    }
}
Also used : AgentRoster(org.jivesoftware.smackx.workgroup.agent.AgentRoster) AgentRosterListener(org.jivesoftware.smackx.workgroup.agent.AgentRosterListener) SmackException(org.jivesoftware.smack.SmackException) Date(java.util.Date) AgentStatus(org.jivesoftware.smackx.workgroup.packet.AgentStatus) Iterator(java.util.Iterator) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Presence(org.jivesoftware.smack.packet.Presence) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List)

Example 3 with AgentStatus

use of org.jivesoftware.smackx.workgroup.packet.AgentStatus in project Spark by igniterealtime.

the class AgentConversations method calculateNumberOfChats.

private void calculateNumberOfChats(AgentRoster agentRoster) {
    int counter = 0;
    // 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);
}
Also used : AgentStatus(org.jivesoftware.smackx.workgroup.packet.AgentStatus) Iterator(java.util.Iterator) Presence(org.jivesoftware.smack.packet.Presence)

Example 4 with AgentStatus

use of org.jivesoftware.smackx.workgroup.packet.AgentStatus in project Spark by igniterealtime.

the class OnlineAgents method buildTooltip.

private String buildTooltip(Presence presence) {
    if (!presence.isAvailable()) {
        return FpRes.getString("message.user.not.logged.in");
    }
    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();
    StringBuilder buf = new StringBuilder();
    buf.append("<html>");
    buf.append("<body>");
    buf.append("<table>");
    while (iter.hasNext()) {
        AgentStatus.ChatInfo chatInfo = iter.next();
        Date startDate = chatInfo.getDate();
        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();
}
Also used : AgentStatus(org.jivesoftware.smackx.workgroup.packet.AgentStatus) Date(java.util.Date)

Aggregations

AgentStatus (org.jivesoftware.smackx.workgroup.packet.AgentStatus)4 Date (java.util.Date)3 Iterator (java.util.Iterator)3 Presence (org.jivesoftware.smack.packet.Presence)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 JList (javax.swing.JList)2 SmackException (org.jivesoftware.smack.SmackException)2 AgentRoster (org.jivesoftware.smackx.workgroup.agent.AgentRoster)2 AgentRosterListener (org.jivesoftware.smackx.workgroup.agent.AgentRosterListener)2 SwingWorker (org.jivesoftware.spark.util.SwingWorker)2