1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

pep: improve pep event filter

This commit is contained in:
Florian Schmaus 2020-04-13 22:36:36 +02:00
parent 7f027bd339
commit 6c3cd53567
2 changed files with 9 additions and 4 deletions

View file

@ -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);
}

View file

@ -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<PepListener> 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<E extends ExtensionElement> {