Search in sources :

Example 1 with PacketExtension

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

the class OfflineMessageStoreTest method shouldStoreEmptyChatMessagesWithOtherExtensions.

@Test
public void shouldStoreEmptyChatMessagesWithOtherExtensions() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    PacketExtension packetExtension2 = new PacketExtension("received", "urn:xmpp:receipts");
    message.addExtension(packetExtension2);
    assertTrue(OfflineMessageStore.shouldStoreMessage(message));
}
Also used : PacketExtension(org.xmpp.packet.PacketExtension) Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 2 with PacketExtension

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

the class OfflineMessageStoreTest method shouldNotStoreEmptyChatMessagesWithOnlyChatStatesAndThread.

@Test
public void shouldNotStoreEmptyChatMessagesWithOnlyChatStatesAndThread() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setThread("1234");
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
Also used : PacketExtension(org.xmpp.packet.PacketExtension) Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 3 with PacketExtension

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

the class OfflineMessageStoreTest method shouldNotStoreEmptyChatMessagesWithOnlyChatStates.

@Test
public void shouldNotStoreEmptyChatMessagesWithOnlyChatStates() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
Also used : PacketExtension(org.xmpp.packet.PacketExtension) Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 4 with PacketExtension

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

the class PEPService method sendNotification.

@Override
public void sendNotification(Node node, Message message, JID recipientJID) {
    message.setTo(recipientJID);
    message.setFrom(getAddress());
    message.setID(StringUtils.randomString(8));
    // If the recipient subscribed with a bare JID and this PEPService can retrieve
    // presence information for the recipient, collect all of their full JIDs and
    // send the notification to each below.
    Set<JID> recipientFullJIDs = new HashSet<>();
    if (XMPPServer.getInstance().isLocal(recipientJID)) {
        if (recipientJID.getResource() == null) {
            for (ClientSession clientSession : SessionManager.getInstance().getSessions(recipientJID.getNode())) {
                recipientFullJIDs.add(clientSession.getAddress());
            }
        }
    } else {
        // Since recipientJID is not local, try to get presence info from cached known remote
        // presences.
        // TODO: OF-605 the old code depends on a cache that would contain presence state on all (?!) JIDS on all (?!)
        // remote domains. As we cannot depend on this information to be correct (even if we could ensure that this
        // potentially unlimited amount of data would indeed be manageable in the first place), this code was removed.
        recipientFullJIDs.add(recipientJID);
    }
    if (recipientFullJIDs.isEmpty()) {
        router.route(message);
        return;
    }
    for (JID recipientFullJID : recipientFullJIDs) {
        // to the service owner.
        try {
            JID publisher = null;
            // Get the ID of the node that had an item published to or retracted from.
            Element itemsElement = message.getElement().element("event").element("items");
            String nodeID = itemsElement.attributeValue("node");
            // Get the ID of the item that was published or retracted.
            String itemID = null;
            Element itemElement = itemsElement.element("item");
            if (itemElement == null) {
                Element retractElement = itemsElement.element("retract");
                if (retractElement != null) {
                    itemID = retractElement.attributeValue("id");
                }
            } else {
                itemID = itemElement.attributeValue("id");
            }
            // Check if the recipientFullJID is interested in notifications for this node.
            // If the recipient has not yet requested any notification filtering, continue and send
            // the notification.
            EntityCapabilities entityCaps = entityCapsManager.getEntityCapabilities(recipientFullJID);
            if (entityCaps != null) {
                if (!entityCaps.containsFeature(nodeID + "+notify")) {
                    return;
                }
            }
            // This full JID will be used as the "replyto" address in the addressing extension.
            if (node.isCollectionNode()) {
                for (Node leafNode : node.getNodes()) {
                    if (leafNode.getNodeID().equals(nodeID)) {
                        publisher = leafNode.getPublishedItem(itemID).getPublisher();
                        // Ensure the recipientJID has access to receive notifications for items published to the leaf node.
                        AccessModel accessModel = leafNode.getAccessModel();
                        if (!accessModel.canAccessItems(leafNode, recipientFullJID, publisher)) {
                            return;
                        }
                        break;
                    }
                }
            } else {
                publisher = node.getPublishedItem(itemID).getPublisher();
            }
            // Ensure the recipient is subscribed to the service owner's (publisher's) presence.
            if (canProbePresence(publisher, recipientFullJID)) {
                Element addresses = DocumentHelper.createElement(QName.get("addresses", "http://jabber.org/protocol/address"));
                Element address = addresses.addElement("address");
                address.addAttribute("type", "replyto");
                address.addAttribute("jid", publisher.toString());
                Message extendedMessage = message.createCopy();
                extendedMessage.addExtension(new PacketExtension(addresses));
                extendedMessage.setTo(recipientFullJID);
                router.route(extendedMessage);
            }
        } catch (IndexOutOfBoundsException e) {
        // Do not add addressing extension to message.
        } catch (UserNotFoundException e) {
            // Do not add addressing extension to message.
            router.route(message);
        } catch (NullPointerException e) {
            try {
                if (canProbePresence(getAddress(), recipientFullJID)) {
                    message.setTo(recipientFullJID);
                }
            } catch (UserNotFoundException e1) {
            // Do nothing
            }
            router.route(message);
        }
    }
}
Also used : PacketExtension(org.xmpp.packet.PacketExtension) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) AccessModel(org.jivesoftware.openfire.pubsub.models.AccessModel) Element(org.dom4j.Element) CollectionNode(org.jivesoftware.openfire.pubsub.CollectionNode) Node(org.jivesoftware.openfire.pubsub.Node) EntityCapabilities(org.jivesoftware.openfire.entitycaps.EntityCapabilities) ClientSession(org.jivesoftware.openfire.session.ClientSession) HashSet(java.util.HashSet)

Aggregations

Message (org.xmpp.packet.Message)4 PacketExtension (org.xmpp.packet.PacketExtension)4 Test (org.junit.Test)3 HashSet (java.util.HashSet)1 Element (org.dom4j.Element)1 EntityCapabilities (org.jivesoftware.openfire.entitycaps.EntityCapabilities)1 CollectionNode (org.jivesoftware.openfire.pubsub.CollectionNode)1 Node (org.jivesoftware.openfire.pubsub.Node)1 AccessModel (org.jivesoftware.openfire.pubsub.models.AccessModel)1 ClientSession (org.jivesoftware.openfire.session.ClientSession)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 JID (org.xmpp.packet.JID)1