Search in sources :

Example 1 with AgentRosterListener

use of org.jivesoftware.smackx.workgroup.agent.AgentRosterListener 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 AgentRosterListener

use of org.jivesoftware.smackx.workgroup.agent.AgentRosterListener 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)

Aggregations

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