1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 09:09:38 +02:00

Add support for "Caps Optimizations"

Smack's previous entity caps implementation assumed that an entity lost
its entity caps feature as soon as a presence without caps from that
entity was received. But according to XEP-0115 § 8.4, this is a
perfectly normal optimization technique. We now reset the caps state
after an available presence becomes unavailable.

Also introduce PresenceEventListener, which is required for this
feature.

Also make Roster.preApprove() take a BareJid as argument.

Fixes SMACK-723.
This commit is contained in:
Florian Schmaus 2016-06-30 17:01:46 +02:00
parent 4248fbbb89
commit d07ed60737
8 changed files with 280 additions and 22 deletions

View file

@ -27,9 +27,10 @@ import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.roster.AbstractPresenceEventListener;
import org.jivesoftware.smack.roster.Roster;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.filter.NotFilter;
import org.jivesoftware.smack.filter.PresenceTypeFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.AndFilter;
@ -47,6 +48,7 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.util.cache.LruCache;
@ -95,8 +97,6 @@ public final class EntityCapsManager extends Manager {
private static final StanzaFilter PRESENCES_WITH_CAPS = new AndFilter(new StanzaTypeFilter(Presence.class), new StanzaExtensionFilter(
ELEMENT, NAMESPACE));
private static final StanzaFilter PRESENCES_WITHOUT_CAPS = new AndFilter(new StanzaTypeFilter(Presence.class), new NotFilter(new StanzaExtensionFilter(
ELEMENT, NAMESPACE)));
/**
* Map of "node + '#' + hash" to DiscoverInfo data
@ -328,15 +328,12 @@ public final class EntityCapsManager extends Manager {
}, PRESENCES_WITH_CAPS);
connection.addAsyncStanzaListener(new StanzaListener() {
Roster.getInstanceFor(connection).addPresenceEventListener(new AbstractPresenceEventListener() {
@Override
public void processPacket(Stanza packet) {
// always remove the JID from the map, even if entityCaps are
// disabled
Jid from = packet.getFrom();
public void presenceUnavailable(FullJid from, Presence presence) {
JID_TO_NODEVER_CACHE.remove(from);
}
}, PRESENCES_WITHOUT_CAPS);
});
connection.addPacketSendingListener(new StanzaListener() {
@Override