Search in sources :

Example 66 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class LocalMUCRoom method createPresence.

@Override
public Presence createPresence(Presence.Type presenceType) throws UnauthorizedException {
    Presence presence = new Presence();
    presence.setType(presenceType);
    presence.setFrom(role.getRoleAddress());
    return presence;
}
Also used : Presence(org.xmpp.packet.Presence) UpdatePresence(org.jivesoftware.openfire.muc.cluster.UpdatePresence)

Example 67 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class LocalMUCRoom method kickOccupant.

@Override
public Presence kickOccupant(JID jid, JID actorJID, String actorNickname, String reason) throws NotAllowedException {
    // Update the presence with the new role and inform all occupants
    Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.none);
    if (updatedPresence != null) {
        Element frag = updatedPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
        // Add the status code 307 that indicates that the user was kicked
        frag.addElement("status").addAttribute("code", "307");
        // Add the reason why the user was kicked
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }
        // Effectively kick the occupant from the room
        kickPresence(updatedPresence, actorJID, actorNickname);
        //Inform the other occupants that user has been kicked
        broadcastPresence(updatedPresence, false);
    }
    return updatedPresence;
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence) UpdatePresence(org.jivesoftware.openfire.muc.cluster.UpdatePresence)

Example 68 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class PubSubEngine method presenceSubscriptionRequired.

/**
     * Requests the pubsub service to unsubscribe from the presence of the user. If the service
     * was not subscribed to the user's presence or any node still requires to be subscribed to
     * the user presence then do nothing.
     *
     * @param service the PubSub service this action is to be performed for.
     * @param node the node that originated the unsubscription request.
     * @param user the JID of the affiliate to unsubscribe from his presence.
     */
public static void presenceSubscriptionRequired(PubSubService service, Node node, JID user) {
    Map<String, String> fullPresences = service.getBarePresences().get(user.toString());
    if (fullPresences == null || fullPresences.isEmpty()) {
        Presence subscription = new Presence(Presence.Type.subscribe);
        subscription.setTo(user);
        subscription.setFrom(service.getAddress());
        service.send(subscription);
    // Sending subscription requests based on received presences may generate
    // that a sunscription request is sent to an offline user (since offline
    // presences are not stored in the service's "barePresences"). However, this
    // not optimal algorithm shouldn't bother the user since the user's server
    // should reply when already subscribed to the user's presence instead of
    // asking the user to accept the subscription request.
    }
}
Also used : Presence(org.xmpp.packet.Presence)

Example 69 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class PubSubEngine method presenceSubscriptionNotRequired.

/**
     * Requests the pubsub service to subscribe to the presence of the user. If the service
     * has already subscribed to the user's presence then do nothing.
     *
     * @param service the PubSub service this action is to be performed for.
     * @param node the node that originated the subscription request.
     * @param user the JID of the affiliate to subscribe to his presence.
     */
public static void presenceSubscriptionNotRequired(PubSubService service, Node node, JID user) {
    // Check that no node is requiring to be subscribed to this user
    for (Node hostedNode : service.getNodes()) {
        if (hostedNode.isPresenceBasedDelivery(user)) {
            // Do not unsubscribe since presence subscription is still required
            return;
        }
    }
    // Unscribe from the user presence
    Presence subscription = new Presence(Presence.Type.unsubscribe);
    subscription.setTo(user);
    subscription.setFrom(service.getAddress());
    service.send(subscription);
}
Also used : Presence(org.xmpp.packet.Presence)

Example 70 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class PubSubEngine method process.

/**
     * Handles Presence packets sent to the pubsub service. Only process available and not
     * available presences.
     *
     * @param service the PubSub service this action is to be performed for.
     * @param presence the Presence packet sent to the pubsub service.
     */
public void process(PubSubService service, Presence presence) {
    if (presence.isAvailable()) {
        JID subscriber = presence.getFrom();
        Map<String, String> fullPresences = service.getBarePresences().get(subscriber.toBareJID());
        if (fullPresences == null) {
            synchronized (subscriber.toBareJID().intern()) {
                fullPresences = service.getBarePresences().get(subscriber.toBareJID());
                if (fullPresences == null) {
                    fullPresences = new ConcurrentHashMap<>();
                    service.getBarePresences().put(subscriber.toBareJID(), fullPresences);
                }
            }
        }
        Presence.Show show = presence.getShow();
        fullPresences.put(subscriber.toString(), show == null ? "online" : show.name());
    } else if (presence.getType() == Presence.Type.unavailable) {
        JID subscriber = presence.getFrom();
        Map<String, String> fullPresences = service.getBarePresences().get(subscriber.toBareJID());
        if (fullPresences != null) {
            fullPresences.remove(subscriber.toString());
            if (fullPresences.isEmpty()) {
                service.getBarePresences().remove(subscriber.toBareJID());
            }
        }
    }
}
Also used : JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

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