1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 14:02:06 +01:00

Fix sending pubsub events for empty item

XEP-0060 allows no elements on second level of nodes.

Modified-by: Florian Schmaus <flo@geekplace.eu>
This commit is contained in:
damencho 2015-12-05 23:08:02 -06:00 committed by Florian Schmaus
parent feff081547
commit 46f0110949

View file

@ -701,6 +701,7 @@ abstract public class Node
{ {
private final String firstElement; private final String firstElement;
private final String secondElement; private final String secondElement;
private final boolean allowEmpty;
EventContentFilter(String elementName) EventContentFilter(String elementName)
{ {
@ -711,6 +712,8 @@ abstract public class Node
{ {
firstElement = firstLevelEelement; firstElement = firstLevelEelement;
secondElement = secondLevelElement; secondElement = secondLevelElement;
allowEmpty = firstElement.equals(EventElementType.items.toString())
&& "item".equals(secondLevelElement);
} }
public boolean acceptSpecific(Message message) { public boolean acceptSpecific(Message message) {
@ -736,6 +739,13 @@ abstract public class Node
{ {
List<ExtensionElement> secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions(); List<ExtensionElement> 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 <items/> element;"
if (allowEmpty && secondLevelList.isEmpty()) {
return true;
}
if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement)) if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement))
return true; return true;
} }