From 46f01109499ceca81a28113c0384a893cdc632ca Mon Sep 17 00:00:00 2001 From: damencho Date: Sat, 5 Dec 2015 23:08:02 -0600 Subject: [PATCH] Fix sending pubsub events for empty item XEP-0060 allows no elements on second level of nodes. Modified-by: Florian Schmaus --- .../main/java/org/jivesoftware/smackx/pubsub/Node.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java index 32946f486..954c92328 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java @@ -701,6 +701,7 @@ abstract public class Node { private final String firstElement; private final String secondElement; + private final boolean allowEmpty; EventContentFilter(String elementName) { @@ -711,6 +712,8 @@ abstract public class Node { firstElement = firstLevelEelement; secondElement = secondLevelElement; + allowEmpty = firstElement.equals(EventElementType.items.toString()) + && "item".equals(secondLevelElement); } public boolean acceptSpecific(Message message) { @@ -736,6 +739,13 @@ abstract public class Node { List secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions(); + // XEP-0060 allows no elements on second level for notifications. See schema or + // for example ยง 4.3: + // "although event notifications MUST include an empty element;" + if (allowEmpty && secondLevelList.isEmpty()) { + return true; + } + if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement)) return true; }