Search in sources :

Example 26 with Presence

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

the class LocalMUCRoom method changeOccupantRole.

/**
     * Updates the presence of the given user with the new role information. Do nothing if the given
     * jid is not present in the room.
     *
     * @param jid the full jid of the user to update his/her role.
     * @param newRole the new role for the JID.
     * @return the updated presence of the user or null if none.
     * @throws NotAllowedException If trying to change the moderator role to an owner or an admin.
     */
private Presence changeOccupantRole(JID jid, MUCRole.Role newRole) throws NotAllowedException {
    // Try looking the role in the bare JID list
    MUCRole role = occupantsByFullJID.get(jid);
    //            }
    if (role != null) {
        if (role.isLocal()) {
            // Update the presence with the new role
            role.setRole(newRole);
            // Notify the other cluster nodes to update the occupant
            CacheFactory.doClusterTask(new UpdateOccupant(this, role));
            // Prepare a new presence to be sent to all the room occupants
            return role.getPresence().createCopy();
        } else {
            // Ask the cluster node hosting the occupant to make the changes. Note that if the change
            // is not allowed a NotAllowedException will be thrown
            Element element = (Element) CacheFactory.doSynchronousClusterTask(new UpdateOccupantRequest(this, role.getNickname(), null, newRole), role.getNodeID().toByteArray());
            if (element != null) {
                // Prepare a new presence to be sent to all the room occupants
                return new Presence(element, true);
            } else {
                throw new NotAllowedException();
            }
        }
    }
    return null;
}
Also used : UpdateOccupant(org.jivesoftware.openfire.muc.cluster.UpdateOccupant) MUCRole(org.jivesoftware.openfire.muc.MUCRole) NotAllowedException(org.jivesoftware.openfire.muc.NotAllowedException) Element(org.dom4j.Element) UpdateOccupantRequest(org.jivesoftware.openfire.muc.cluster.UpdateOccupantRequest) Presence(org.xmpp.packet.Presence) UpdatePresence(org.jivesoftware.openfire.muc.cluster.UpdatePresence)

Example 27 with Presence

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

the class RemoteMUCRole method readExternal.

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    serviceDomain = ExternalizableUtil.getInstance().readSafeUTF(in);
    presence = new Presence((Element) ExternalizableUtil.getInstance().readSerializable(in), true);
    role = Role.values()[ExternalizableUtil.getInstance().readInt(in)];
    affiliation = Affiliation.values()[ExternalizableUtil.getInstance().readInt(in)];
    nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
    voiceOnly = ExternalizableUtil.getInstance().readBoolean(in);
    roleAddress = (JID) ExternalizableUtil.getInstance().readSerializable(in);
    userAddress = (JID) ExternalizableUtil.getInstance().readSerializable(in);
    nodeID = NodeID.getInstance(ExternalizableUtil.getInstance().readByteArray(in));
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 28 with Presence

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

the class MultiplexerPacketDeliverer method handleUnprocessedPacket.

private void handleUnprocessedPacket(Packet packet) {
    if (packet instanceof Message) {
        messageStrategy.storeOffline((Message) packet);
    } else if (packet instanceof Presence) {
    // presence packets are dropped silently
    //dropPacket(packet);
    } else if (packet instanceof IQ) {
        IQ iq = (IQ) packet;
        // Check if we need to unwrap the packet
        Element child = iq.getChildElement();
        if (child != null && "session".equals(child.getName()) && "http://jabber.org/protocol/connectionmanager".equals(child.getNamespacePrefix())) {
            Element send = child.element("send");
            if (send != null) {
                // Unwrap packet
                Element wrappedElement = (Element) send.elements().get(0);
                if ("message".equals(wrappedElement.getName())) {
                    handleUnprocessedPacket(new Message(wrappedElement));
                }
            }
        } else {
            // IQ packets are logged but dropped
            Log.warn(LocaleUtils.getLocalizedString("admin.error.routing") + "\n" + packet.toString());
        }
    }
}
Also used : Message(org.xmpp.packet.Message) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Example 29 with Presence

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

the class WorkgroupPresence method sendPresence.

/**
     * Sends the presence of the workgroup to the specified JID address.
     *
     * @param address the XMPP address that will receive the presence of the workgroup.
     */
public void sendPresence(JID address) {
    Presence presence = new Presence();
    presence.setTo(address);
    presence.setFrom(workgroup.getJID());
    Presence.Type type;
    if (workgroup.isAvailable()) {
        type = null;
        // Add the a child element that will contain information about the workgroup
        Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
        // Add the last modification date of the workgroup
        child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
    } else {
        type = Presence.Type.unavailable;
        // Add the a child element that will contain information about the workgroup
        Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
        // Add the last modification date of the workgroup
        child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
    }
    presence.setType(type);
    workgroup.send(presence);
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 30 with Presence

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

the class NonPersistantRosterProcessor method process.

@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
    Presence myPacket = (Presence) packet;
    if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable) && !myPacket.getElement().getStringValue().equals("Connecting")) {
        String username = getUsernameFromJid(to);
        Log.debug("Processing packet in NonPersistantRosterProcessor for " + subdomain + "and user " + username + " Packet: " + packet.toString());
        try {
            Roster roster = _rosterManager.getRoster(username);
            Collection<RosterItem> items = roster.getRosterItems();
            for (RosterItem item : items) {
                String itemName = item.getJid().toString();
                if (itemName.contains(subdomain)) {
                    Log.debug("Removing contact " + item.getJid().toString() + " from contact list.");
                    roster.deleteRosterItem(item.getJid(), false);
                }
            }
        } catch (Exception e) {
            Log.debug("Execption occured when cleaning up the Roster.", e);
            e.printStackTrace();
        }
    }
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) Presence(org.xmpp.packet.Presence) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException)

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