From 6c3cd535672f7259e651beced24517b9659a95f0 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 13 Apr 2020 22:36:36 +0200 Subject: [PATCH] pep: improve pep event filter --- .../smack/filter/jidtype/FromJidTypeFilter.java | 2 ++ .../java/org/jivesoftware/smackx/pep/PepManager.java | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/jidtype/FromJidTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/jidtype/FromJidTypeFilter.java index c9326c175..3bcd71b22 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/jidtype/FromJidTypeFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/jidtype/FromJidTypeFilter.java @@ -28,6 +28,8 @@ import org.jxmpp.jid.Jid; */ public class FromJidTypeFilter extends AbstractJidTypeFilter { + public static final FromJidTypeFilter ENTITY_BARE_JID = new FromJidTypeFilter(JidType.EntityBareJid); + public FromJidTypeFilter(JidType jidType) { super(jidType); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PepManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PepManager.java index c830fcbf7..0ec19bf8a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PepManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PepManager.java @@ -33,8 +33,8 @@ import org.jivesoftware.smack.StanzaListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.filter.AndFilter; +import org.jivesoftware.smack.filter.MessageTypeFilter; import org.jivesoftware.smack.filter.StanzaFilter; -import org.jivesoftware.smack.filter.jidtype.AbstractJidTypeFilter.JidType; import org.jivesoftware.smack.filter.jidtype.FromJidTypeFilter; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; @@ -92,8 +92,11 @@ public final class PepManager extends Manager { return pepManager; } - private static final StanzaFilter FROM_BARE_JID_WITH_EVENT_EXTENSION_FILTER = new AndFilter( - new FromJidTypeFilter(JidType.BareJid), + // TODO: Ideally PepManager would re-use PubSubManager for this. But the functionality in PubSubManager does not yet + // exist. + private static final StanzaFilter PEP_EVENTS_FILTER = new AndFilter( + MessageTypeFilter.HEADLINE, + FromJidTypeFilter.ENTITY_BARE_JID, EventItemsExtensionFilter.INSTANCE); private final Set pepListeners = new CopyOnWriteArraySet<>(); @@ -168,7 +171,7 @@ public final class PepManager extends Manager { } }; // TODO Add filter to check if from supports PubSub as per xep163 2 2.4 - connection.addSyncStanzaListener(packetListener, FROM_BARE_JID_WITH_EVENT_EXTENSION_FILTER); + connection.addSyncStanzaListener(packetListener, PEP_EVENTS_FILTER); } private static final class PepEventListenerCoupling {