mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-21 18:17:58 +01:00
[extensions] Deprecate old-style PepManager PEP listeners
This commit is contained in:
parent
15499ad1f8
commit
ccc785062e
4 changed files with 48 additions and 94 deletions
|
@ -253,7 +253,10 @@ public final class PepManager extends Manager {
|
|||
*
|
||||
* @param pepListener a roster exchange listener.
|
||||
* @return true if pepListener was added.
|
||||
* @deprecated use {@link #addPepEventListener(String, Class, PepEventListener)} instead.
|
||||
*/
|
||||
// TODO: Remove in Smack 4.5
|
||||
@Deprecated
|
||||
public boolean addPepListener(PepListener pepListener) {
|
||||
return pepListeners.add(pepListener);
|
||||
}
|
||||
|
@ -263,7 +266,10 @@ public final class PepManager extends Manager {
|
|||
*
|
||||
* @param pepListener a roster exchange listener.
|
||||
* @return true, if pepListener was removed.
|
||||
* @deprecated use {@link #removePepEventListener(PepEventListener)} instead.
|
||||
*/
|
||||
// TODO: Remove in Smack 4.5.
|
||||
@Deprecated
|
||||
public boolean removePepListener(PepListener pepListener) {
|
||||
return pepListeners.remove(pepListener);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.OMEMO_NAMESPACE_V_AXOLOTL;
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.PEP_NODE_DEVICE_LIST_NOTIFY;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -39,7 +38,6 @@ import org.jivesoftware.smack.Manager;
|
|||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
@ -71,10 +69,9 @@ import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
|||
import org.jivesoftware.smackx.omemo.trust.OmemoTrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
||||
import org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage;
|
||||
import org.jivesoftware.smackx.omemo.util.OmemoConstants;
|
||||
import org.jivesoftware.smackx.pep.PepEventListener;
|
||||
import org.jivesoftware.smackx.pep.PepManager;
|
||||
import org.jivesoftware.smackx.pubsub.EventElement;
|
||||
import org.jivesoftware.smackx.pubsub.ItemsExtension;
|
||||
import org.jivesoftware.smackx.pubsub.PayloadItem;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubException;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||
|
||||
|
@ -101,6 +98,8 @@ public final class OmemoManager extends Manager {
|
|||
private final HashSet<OmemoMessageListener> omemoMessageListeners = new HashSet<>();
|
||||
private final HashSet<OmemoMucMessageListener> omemoMucMessageListeners = new HashSet<>();
|
||||
|
||||
private final PepManager pepManager;
|
||||
|
||||
private OmemoTrustCallback trustCallback;
|
||||
|
||||
private BareJid ownJid;
|
||||
|
@ -116,6 +115,7 @@ public final class OmemoManager extends Manager {
|
|||
super(connection);
|
||||
|
||||
service = OmemoService.getInstance();
|
||||
pepManager = PepManager.getInstanceFor(connection);
|
||||
|
||||
this.deviceId = deviceId;
|
||||
|
||||
|
@ -134,9 +134,6 @@ public final class OmemoManager extends Manager {
|
|||
|
||||
// StanzaListeners
|
||||
resumeStanzaAndPEPListeners();
|
||||
|
||||
// Announce OMEMO support
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(PEP_NODE_DEVICE_LIST_NOTIFY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -247,7 +244,6 @@ public final class OmemoManager extends Manager {
|
|||
}
|
||||
|
||||
getOmemoService().init(new LoggedInOmemoManager(this));
|
||||
ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(PEP_NODE_DEVICE_LIST_NOTIFY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -889,16 +885,14 @@ public final class OmemoManager extends Manager {
|
|||
* after {@link #stopStanzaAndPEPListeners()} was called.
|
||||
*/
|
||||
public void resumeStanzaAndPEPListeners() {
|
||||
PepManager pepManager = PepManager.getInstanceFor(connection());
|
||||
CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());
|
||||
|
||||
// Remove listeners to avoid them getting added twice
|
||||
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
||||
carbonManager.removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||
pepManager.removePepListener(this::deviceListUpdateListener);
|
||||
|
||||
// Add listeners
|
||||
pepManager.addPepListener(this::deviceListUpdateListener);
|
||||
pepManager.addPepEventListener(OmemoConstants.PEP_NODE_DEVICE_LIST, OmemoDeviceListElement.class, pepOmemoDeviceListEventListener);
|
||||
connection().addAsyncStanzaListener(this::internalOmemoMessageStanzaListener, OmemoManager::isOmemoMessage);
|
||||
carbonManager.addCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||
}
|
||||
|
@ -907,7 +901,7 @@ public final class OmemoManager extends Manager {
|
|||
* Remove active stanza listeners needed for OMEMO.
|
||||
*/
|
||||
public void stopStanzaAndPEPListeners() {
|
||||
PepManager.getInstanceFor(connection()).removePepListener(this::deviceListUpdateListener);
|
||||
pepManager.removePepEventListener(pepOmemoDeviceListEventListener);
|
||||
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
||||
CarbonManager.getInstanceFor(connection()).removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||
}
|
||||
|
@ -992,41 +986,17 @@ public final class OmemoManager extends Manager {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* PEPListener that listens for OMEMO deviceList updates.
|
||||
*/
|
||||
private void deviceListUpdateListener(EntityBareJid from, EventElement event, Message message) {
|
||||
// Unknown sender, no more work to do.
|
||||
if (from == null) {
|
||||
// TODO: This DOES happen for some reason. Figure out when...
|
||||
return;
|
||||
}
|
||||
|
||||
for (ExtensionElement items : event.getExtensions()) {
|
||||
if (!(items instanceof ItemsExtension)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (ExtensionElement item : ((ItemsExtension) items).getExtensions()) {
|
||||
if (!(item instanceof PayloadItem<?>)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PayloadItem<?> payloadItem = (PayloadItem<?>) item;
|
||||
|
||||
if (!(payloadItem.getPayload() instanceof OmemoDeviceListElement)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnnecessaryLambda")
|
||||
private final PepEventListener<OmemoDeviceListElement> pepOmemoDeviceListEventListener =
|
||||
(from, receivedDeviceList, id, message) -> {
|
||||
// Device List <list>
|
||||
OmemoCachedDeviceList deviceList;
|
||||
OmemoDeviceListElement receivedDeviceList = (OmemoDeviceListElement) payloadItem.getPayload();
|
||||
try {
|
||||
getOmemoService().getOmemoStoreBackend().mergeCachedDeviceList(getOwnDevice(), from,
|
||||
receivedDeviceList);
|
||||
|
||||
if (!from.asBareJid().equals(getOwnJid())) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
deviceList = getOmemoService().cleanUpDeviceList(getOwnDevice());
|
||||
|
@ -1034,7 +1004,7 @@ public final class OmemoManager extends Manager {
|
|||
LOGGER.log(Level.SEVERE,
|
||||
"IOException while processing OMEMO PEP device updates. Message: " + message,
|
||||
e);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
final OmemoDeviceListElement_VAxolotl newDeviceList = new OmemoDeviceListElement_VAxolotl(deviceList);
|
||||
|
||||
|
@ -1054,9 +1024,7 @@ public final class OmemoManager extends Manager {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* StanzaFilter that filters messages containing a OMEMO element.
|
||||
|
|
|
@ -31,7 +31,6 @@ public final class OmemoConstants {
|
|||
|
||||
// PubSub Node names
|
||||
public static final String PEP_NODE_DEVICE_LIST = OMEMO_NAMESPACE_V_AXOLOTL + ".devicelist";
|
||||
public static final String PEP_NODE_DEVICE_LIST_NOTIFY = PEP_NODE_DEVICE_LIST + "+notify";
|
||||
public static final String PEP_NODE_BUNDLES = OMEMO_NAMESPACE_V_AXOLOTL + ".bundles";
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,12 +68,10 @@ import org.jivesoftware.smackx.ox.store.definition.OpenPgpStore;
|
|||
import org.jivesoftware.smackx.ox.store.definition.OpenPgpTrustStore;
|
||||
import org.jivesoftware.smackx.ox.util.OpenPgpPubSubUtil;
|
||||
import org.jivesoftware.smackx.ox.util.SecretKeyBackupHelper;
|
||||
import org.jivesoftware.smackx.pep.PepEventListener;
|
||||
import org.jivesoftware.smackx.pep.PepListener;
|
||||
import org.jivesoftware.smackx.pep.PepManager;
|
||||
import org.jivesoftware.smackx.pubsub.EventElement;
|
||||
import org.jivesoftware.smackx.pubsub.ItemsExtension;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PayloadItem;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubException;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubFeature;
|
||||
|
||||
|
@ -172,6 +170,9 @@ public final class OpenPgpManager extends Manager {
|
|||
private final Set<SignElementReceivedListener> signElementReceivedListeners = new HashSet<>();
|
||||
private final Set<CryptElementReceivedListener> cryptElementReceivedListeners = new HashSet<>();
|
||||
|
||||
@SuppressWarnings("UnnecessaryLambda")
|
||||
private final PepEventListener<PublicKeysListElement> pepPublicKeyListElementListener = (from, listElement, id, message) -> processPublicKeysListElement(from, listElement);;
|
||||
|
||||
/**
|
||||
* Private constructor to avoid instantiation without putting the object into {@code INSTANCES}.
|
||||
*
|
||||
|
@ -278,7 +279,7 @@ public final class OpenPgpManager extends Manager {
|
|||
publishPublicKey(pepManager, pubkeyElement, primaryFingerprint);
|
||||
|
||||
// Subscribe to public key changes
|
||||
PepManager.getInstanceFor(connection()).addPepListener(this::metadataListener);
|
||||
pepManager.addPepEventListener(PEP_NODE_PUBLIC_KEYS, PublicKeysListElement.class, pepPublicKeyListElementListener);
|
||||
ServiceDiscoveryManager.getInstanceFor(connection())
|
||||
.addFeature(PEP_NODE_PUBLIC_KEYS_NOTIFY);
|
||||
}
|
||||
|
@ -380,7 +381,7 @@ public final class OpenPgpManager extends Manager {
|
|||
* Remove the metadata listener. This method is mainly used in tests.
|
||||
*/
|
||||
public void stopMetadataListener() {
|
||||
PepManager.getInstanceFor(connection()).removePepListener(this::metadataListener);
|
||||
pepManager.removePepEventListener(pepPublicKeyListElementListener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -496,26 +497,6 @@ public final class OpenPgpManager extends Manager {
|
|||
Private stuff.
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@link PepListener} that listens for changes to the OX public keys metadata node.
|
||||
*
|
||||
* @see <a href="https://xmpp.org/extensions/xep-0373.html#pubsub-notifications">XEP-0373 §4.4</a>
|
||||
*/
|
||||
private void metadataListener(final EntityBareJid from, final EventElement event, final Message message) {
|
||||
if (PEP_NODE_PUBLIC_KEYS.equals(event.getEvent().getNode())) {
|
||||
Async.go(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ItemsExtension items = (ItemsExtension) event.getExtensions().get(0);
|
||||
PayloadItem<?> payload = (PayloadItem<?>) items.getItems().get(0);
|
||||
PublicKeysListElement listElement = (PublicKeysListElement) payload.getPayload();
|
||||
|
||||
processPublicKeysListElement(from, listElement);
|
||||
}
|
||||
}, "ProcessOXMetadata");
|
||||
}
|
||||
}
|
||||
|
||||
private void processPublicKeysListElement(BareJid contact, PublicKeysListElement listElement) {
|
||||
OpenPgpContact openPgpContact = getOpenPgpContact(contact.asEntityBareJidIfPossible());
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue