private Map<List<NodeSubscription>, List<PublishedItem>> getItemsBySubscriptions(LeafNode leafNode, List<PublishedItem> publishedItems) {
        // Identify which subscriptions can receive each item
        Map<PublishedItem, List<NodeSubscription>> subsByItem = new HashMap<>();

        // Filter affiliate subscriptions and only use approved and configured ones
        Collection<NodeSubscription> subscriptions = getSubscriptions();
        for (PublishedItem publishedItem : publishedItems) {
            for (NodeSubscription subscription : subscriptions) {
                if (subscription.canSendPublicationEvent(leafNode, publishedItem)) {
                    subsByItem.computeIfAbsent(publishedItem, k -> new ArrayList<>()).add(subscription);
                }
            }
        }

        // Identify which items should be sent together to the same subscriptions
        Map<List<NodeSubscription>, List<PublishedItem>> itemsBySubs = new HashMap<>();
        List<PublishedItem> affectedSubscriptions;
        for (PublishedItem publishedItem : subsByItem.keySet()) {
            affectedSubscriptions = itemsBySubs.get(subsByItem.get(publishedItem));
            if (affectedSubscriptions == null) {
                List<PublishedItem> items = new ArrayList<>(publishedItems.size());
                items.add(publishedItem);
                itemsBySubs.put(subsByItem.get(publishedItem), items);
            }
            else {
                affectedSubscriptions.add(publishedItem);
            }
        }
        return itemsBySubs;
    }
Sends an event notification to each affected subscription of the affiliate. If the owner
has many subscriptions from the same full JID then a single notification is going to be
sent including a detail of the subscription IDs for which the notification is being sent.<p>

Event notifications may include notifications of new published items or of items that
were deleted.<p>

The original publication to the node may or may not contain a {@link PublishedItem}. The
subscriptions of the affiliation will be filtered based on the published item (if one was
specified), the subscription status and originating node.

@param notification the message to send containing the event notification.
@param notifySubscriptions list of subscriptions that were affected and are going to be
       included in the notification message. The list should not be empty.
xmppserver/src/main/java/org/jivesoftware/openfire/pubsub/NodeAffiliate.java