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();
}
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();
}
}
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);
}
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();
}
Aggregations