Search in sources :

Example 1 with DiscoItem

use of org.jivesoftware.openfire.disco.DiscoItem in project Openfire by igniterealtime.

the class IQOfflineMessagesHandler method getItems.

@Override
public Iterator<DiscoItem> getItems(String name, String node, JID senderJID) {
    // Mark that offline messages shouldn't be sent when the user becomes available
    stopOfflineFlooding(senderJID);
    List<DiscoItem> answer = new ArrayList<>();
    for (OfflineMessage offlineMessage : messageStore.getMessages(senderJID.getNode(), false)) {
        answer.add(new DiscoItem(senderJID.asBareJID(), offlineMessage.getFrom().toString(), XMPPDateTimeFormat.format(offlineMessage.getCreationDate()), null));
    }
    return answer.iterator();
}
Also used : ArrayList(java.util.ArrayList) DiscoItem(org.jivesoftware.openfire.disco.DiscoItem) OfflineMessage(org.jivesoftware.openfire.OfflineMessage)

Example 2 with DiscoItem

use of org.jivesoftware.openfire.disco.DiscoItem in project Openfire by igniterealtime.

the class PubSubModule method getItems.

@Override
public Iterator<DiscoItem> getItems(String name, String node, JID senderJID) {
    // Check if the service is disabled. Info is not available when disabled.
    if (!isServiceEnabled()) {
        return null;
    }
    List<DiscoItem> answer = new ArrayList<>();
    String serviceDomain = getServiceDomain();
    if (name == null && node == null) {
        // Answer all first level nodes
        for (Node pubNode : rootCollectionNode.getNodes()) {
            if (canDiscoverNode(pubNode)) {
                final DiscoItem item = new DiscoItem(new JID(serviceDomain), pubNode.getName(), pubNode.getNodeID(), null);
                answer.add(item);
            }
        }
    } else if (name == null) {
        Node pubNode = getNode(node);
        if (pubNode != null && canDiscoverNode(pubNode)) {
            if (pubNode.isCollectionNode()) {
                // Answer all nested nodes as items
                for (Node nestedNode : pubNode.getNodes()) {
                    if (canDiscoverNode(nestedNode)) {
                        final DiscoItem item = new DiscoItem(new JID(serviceDomain), nestedNode.getName(), nestedNode.getNodeID(), null);
                        answer.add(item);
                    }
                }
            } else {
                // This is a leaf node so answer the published items which exist on the service
                for (PublishedItem publishedItem : pubNode.getPublishedItems()) {
                    answer.add(new DiscoItem(new JID(serviceDomain), publishedItem.getID(), null, null));
                }
            }
        } else {
            // Answer null to indicate that specified item was not found
            return null;
        }
    }
    return answer.iterator();
}
Also used : JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DiscoItem(org.jivesoftware.openfire.disco.DiscoItem)

Aggregations

ArrayList (java.util.ArrayList)2 DiscoItem (org.jivesoftware.openfire.disco.DiscoItem)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 OfflineMessage (org.jivesoftware.openfire.OfflineMessage)1 JID (org.xmpp.packet.JID)1