use of org.jivesoftware.smackx.workgroup.agent.AgentRoster 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();
}
use of org.jivesoftware.smackx.workgroup.agent.AgentRoster 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();
}
}
Aggregations