Search in sources :

Example 81 with Presence

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;
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 82 with Presence

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;
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence) UserRequest(org.jivesoftware.xmpp.workgroup.request.UserRequest) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 83 with Presence

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);
    }
}
Also used : Presence(org.xmpp.packet.Presence) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 84 with Presence

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);
}
Also used : Message(org.xmpp.packet.Message) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Example 85 with Presence

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);
}
Also used : Packet(org.xmpp.packet.Packet) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) ArrayList(java.util.ArrayList) Presence(org.xmpp.packet.Presence) Date(java.sql.Date)

Aggregations

Presence (org.xmpp.packet.Presence)109 JID (org.xmpp.packet.JID)38 Element (org.dom4j.Element)34 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)20 Message (org.xmpp.packet.Message)17 IQ (org.xmpp.packet.IQ)16 UpdatePresence (org.jivesoftware.openfire.muc.cluster.UpdatePresence)14 NotFoundException (org.jivesoftware.util.NotFoundException)12 ArrayList (java.util.ArrayList)11 MUCRole (org.jivesoftware.openfire.muc.MUCRole)10 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)9 DefaultElement (org.dom4j.tree.DefaultElement)8 IOException (java.io.IOException)7 SQLException (java.sql.SQLException)7 GroupJID (org.jivesoftware.openfire.group.GroupJID)7 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)7 Date (java.util.Date)6 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)6 ConflictException (org.jivesoftware.openfire.muc.ConflictException)6 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)6