use of org.jivesoftware.smackx.workgroup.packet.QueueOverview in project Smack by igniterealtime.
the class AgentSession method handlePacket.
// PacketListener Implementation.
private void handlePacket(Stanza packet) {
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
// The workgroup can send us a number of different presence packets. We
// check for different packet extensions to see what type of presence
// packet it is.
Resourcepart queueName = presence.getFrom().getResourceOrNull();
WorkgroupQueue queue = queues.get(queueName);
// If there isn't already an entry for the queue, create a new one.
if (queue == null) {
queue = new WorkgroupQueue(queueName);
queues.put(queueName, queue);
}
// QueueOverview packet extensions contain basic information about a queue.
QueueOverview queueOverview = (QueueOverview) presence.getExtension(QueueOverview.ELEMENT_NAME, QueueOverview.NAMESPACE);
if (queueOverview != null) {
if (queueOverview.getStatus() == null) {
queue.setStatus(WorkgroupQueue.Status.CLOSED);
} else {
queue.setStatus(queueOverview.getStatus());
}
queue.setAverageWaitTime(queueOverview.getAverageWaitTime());
queue.setOldestEntry(queueOverview.getOldestEntry());
// Fire event.
fireQueueUsersEvent(queue, queueOverview.getStatus(), queueOverview.getAverageWaitTime(), queueOverview.getOldestEntry(), null);
return;
}
// QueueDetails packet extensions contain information about the users in
// a queue.
QueueDetails queueDetails = (QueueDetails) packet.getExtension(QueueDetails.ELEMENT_NAME, QueueDetails.NAMESPACE);
if (queueDetails != null) {
queue.setUsers(queueDetails.getUsers());
// Fire event.
fireQueueUsersEvent(queue, null, -1, null, queueDetails.getUsers());
return;
}
// Notify agent packets gives an overview of agent activity in a queue.
StandardExtensionElement notifyAgents = presence.getExtension("notify-agents", "http://jabber.org/protocol/workgroup");
if (notifyAgents != null) {
int currentChats = Integer.parseInt(notifyAgents.getFirstElement("current-chats", "http://jabber.org/protocol/workgroup").getText());
int maxChats = Integer.parseInt(notifyAgents.getFirstElement("max-chats", "http://jabber.org/protocol/workgroup").getText());
queue.setCurrentChats(currentChats);
queue.setMaxChats(maxChats);
// TODO: might need another event for current chats and max chats of queue
return;
}
} else if (packet instanceof Message) {
Message message = (Message) packet;
// Check if a room invitation was sent and if the sender is the workgroup
MUCUser mucUser = (MUCUser) message.getExtension("x", "http://jabber.org/protocol/muc#user");
MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null;
if (invite != null && workgroupJID.equals(invite.getFrom())) {
String sessionID = null;
Map<String, List<String>> metaData = null;
SessionID sessionIDExt = (SessionID) message.getExtension(SessionID.ELEMENT_NAME, SessionID.NAMESPACE);
if (sessionIDExt != null) {
sessionID = sessionIDExt.getSessionID();
}
MetaData metaDataExt = (MetaData) message.getExtension(MetaData.ELEMENT_NAME, MetaData.NAMESPACE);
if (metaDataExt != null) {
metaData = metaDataExt.getMetaData();
}
this.fireInvitationEvent(message.getFrom(), sessionID, message.getBody(), message.getFrom(), metaData);
}
}
}
Aggregations