use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class RequestQueue method getStatusPresence.
public Presence getStatusPresence() {
Presence queueStatus = new Presence();
queueStatus.setFrom(address);
// Add Notify Queue
Element status = queueStatus.addChildElement("notify-queue", "http://jabber.org/protocol/workgroup");
Element countElement = status.addElement("count");
countElement.setText(Integer.toString(getRequestCount()));
if (getRequestCount() > 0) {
Element oldestElement = status.addElement("oldest");
oldestElement.setText(UTC_FORMAT.format(getFirst().getCreationTime()));
}
Element timeElement = status.addElement("time");
timeElement.setText(Integer.toString(getAverageTime()));
Element statusElement = status.addElement("status");
if (workgroup.getStatus() == Workgroup.Status.OPEN && presenceAvailable) {
statusElement.setText("open");
} else {
queueStatus.setType(Presence.Type.unavailable);
// may be empty but still active
if (getRequestCount() > 0) {
statusElement.setText("active");
} else {
if (workgroup.getStatus() == Workgroup.Status.READY) {
statusElement.setText("ready");
} else {
statusElement.setText("closed");
}
}
}
return queueStatus;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class RequestQueue method getDetailedStatusPresence.
public Presence getDetailedStatusPresence() {
Presence queueStatus = new Presence();
queueStatus.setFrom(address);
if (workgroup.getStatus() == Workgroup.Status.OPEN && presenceAvailable) {
queueStatus.setType(null);
} else {
queueStatus.setType(Presence.Type.unavailable);
}
Element details = queueStatus.addChildElement("notify-queue-details", "http://jabber.org/protocol/workgroup");
int i = 0;
for (UserRequest request : getRequests()) {
Element user = details.addElement("user", "http://jabber.org/protocol/workgroup");
try {
user.addAttribute("jid", request.getUserJID().toString());
// Add Sub-Elements
Element position = user.addElement("position");
position.setText(Integer.toString(i));
Element time = user.addElement("time");
time.setText(Integer.toString(request.getTimeStatus()));
Element joinTime = user.addElement("join-time");
joinTime.setText(UTC_FORMAT.format(request.getCreationTime()));
i++;
} catch (Exception e) {
// Since we are not locking the list of requests while doing this operation (for
// performance reasons) it is possible that the request got accepted or cancelled
// thus generating a NPE
// Remove the request that generated the exception
details.remove(user);
// Log an error if the request still belongs to this queue
if (this.equals(request.getRequestQueue())) {
Log.error(e.getMessage(), e);
}
}
}
return queueStatus;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class RequestQueue method sendDetailedStatus.
public void sendDetailedStatus(JID recipient) {
try {
// queue details
Presence queueStatus = getDetailedStatusPresence();
queueStatus.setTo(recipient);
workgroup.send(queueStatus);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class Workgroup method rejectPacket.
public void rejectPacket(Packet packet, PacketRejectedException e) {
if (packet instanceof IQ) {
IQ reply = new IQ();
reply.setChildElement(((IQ) packet).getChildElement().createCopy());
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
send(reply);
} else if (packet instanceof Presence) {
Presence reply = new Presence();
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
send(reply);
}
// Check if a message notifying the rejection should be sent
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message notification = new Message();
notification.setTo(packet.getFrom());
notification.setFrom(packet.getTo());
notification.setBody(e.getRejectionMessage());
send(notification);
}
Log.warn("Packet was REJECTED " + "by interceptor: " + packet.toXML(), e);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class Workgroup method sendOccupantsInfo.
/**
* Sends information to the agent that requested it about the occupants in the specified
* room. If the room does no longer exist then no information will be returned. This means
* that the chat should be happening at the moment of the query.
*
* @param packet the request sent by the agent.
* @param roomID the id of the room that the agent is requesting information
*/
public void sendOccupantsInfo(IQ packet, String roomID) {
IQ statusPacket = IQ.createResultIQ(packet);
Element occupantsInfo = statusPacket.setChildElement("occupants-info", "http://jivesoftware.com/protocol/workgroup");
occupantsInfo.addAttribute("roomID", roomID);
Map<Packet, java.util.Date> packets = transcripts.get(roomID);
if (packets != null) {
Collection<String> processed = new ArrayList<String>();
for (Packet p : packets.keySet()) {
if (p instanceof Presence) {
Presence presence = (Presence) p;
// Get the JID of the presence's user
String userJID = presence.getChildElement("x", "http://jabber.org/protocol/muc#user").element("item").attributeValue("jid");
// occupant joined the room
if (!processed.contains(userJID)) {
processed.add(userJID);
Element occupantInfo = occupantsInfo.addElement("occupant");
occupantInfo.addElement("jid").setText(userJID);
occupantInfo.addElement("nickname").setText(presence.getFrom().getResource());
occupantInfo.addElement("joined").setText(UTC_FORMAT.format(packets.get(p)));
}
}
}
}
// Send the response
send(statusPacket);
}
Aggregations