mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 02:27: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.
|
* @param pepListener a roster exchange listener.
|
||||||
* @return true if pepListener was added.
|
* @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) {
|
public boolean addPepListener(PepListener pepListener) {
|
||||||
return pepListeners.add(pepListener);
|
return pepListeners.add(pepListener);
|
||||||
}
|
}
|
||||||
|
@ -263,7 +266,10 @@ public final class PepManager extends Manager {
|
||||||
*
|
*
|
||||||
* @param pepListener a roster exchange listener.
|
* @param pepListener a roster exchange listener.
|
||||||
* @return true, if pepListener was removed.
|
* @return true, if pepListener was removed.
|
||||||
|
* @deprecated use {@link #removePepEventListener(PepEventListener)} instead.
|
||||||
*/
|
*/
|
||||||
|
// TODO: Remove in Smack 4.5.
|
||||||
|
@Deprecated
|
||||||
public boolean removePepListener(PepListener pepListener) {
|
public boolean removePepListener(PepListener pepListener) {
|
||||||
return pepListeners.remove(pepListener);
|
return pepListeners.remove(pepListener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smackx.omemo;
|
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.OMEMO_NAMESPACE_V_AXOLOTL;
|
||||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.PEP_NODE_DEVICE_LIST_NOTIFY;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -39,7 +38,6 @@ import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||||
import org.jivesoftware.smack.packet.Stanza;
|
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.OmemoTrustCallback;
|
||||||
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
||||||
import org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage;
|
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.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.PubSubException;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
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<OmemoMessageListener> omemoMessageListeners = new HashSet<>();
|
||||||
private final HashSet<OmemoMucMessageListener> omemoMucMessageListeners = new HashSet<>();
|
private final HashSet<OmemoMucMessageListener> omemoMucMessageListeners = new HashSet<>();
|
||||||
|
|
||||||
|
private final PepManager pepManager;
|
||||||
|
|
||||||
private OmemoTrustCallback trustCallback;
|
private OmemoTrustCallback trustCallback;
|
||||||
|
|
||||||
private BareJid ownJid;
|
private BareJid ownJid;
|
||||||
|
@ -116,6 +115,7 @@ public final class OmemoManager extends Manager {
|
||||||
super(connection);
|
super(connection);
|
||||||
|
|
||||||
service = OmemoService.getInstance();
|
service = OmemoService.getInstance();
|
||||||
|
pepManager = PepManager.getInstanceFor(connection);
|
||||||
|
|
||||||
this.deviceId = deviceId;
|
this.deviceId = deviceId;
|
||||||
|
|
||||||
|
@ -134,9 +134,6 @@ public final class OmemoManager extends Manager {
|
||||||
|
|
||||||
// StanzaListeners
|
// StanzaListeners
|
||||||
resumeStanzaAndPEPListeners();
|
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));
|
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.
|
* after {@link #stopStanzaAndPEPListeners()} was called.
|
||||||
*/
|
*/
|
||||||
public void resumeStanzaAndPEPListeners() {
|
public void resumeStanzaAndPEPListeners() {
|
||||||
PepManager pepManager = PepManager.getInstanceFor(connection());
|
|
||||||
CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());
|
CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());
|
||||||
|
|
||||||
// Remove listeners to avoid them getting added twice
|
// Remove listeners to avoid them getting added twice
|
||||||
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
||||||
carbonManager.removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
carbonManager.removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||||
pepManager.removePepListener(this::deviceListUpdateListener);
|
|
||||||
|
|
||||||
// Add listeners
|
// Add listeners
|
||||||
pepManager.addPepListener(this::deviceListUpdateListener);
|
pepManager.addPepEventListener(OmemoConstants.PEP_NODE_DEVICE_LIST, OmemoDeviceListElement.class, pepOmemoDeviceListEventListener);
|
||||||
connection().addAsyncStanzaListener(this::internalOmemoMessageStanzaListener, OmemoManager::isOmemoMessage);
|
connection().addAsyncStanzaListener(this::internalOmemoMessageStanzaListener, OmemoManager::isOmemoMessage);
|
||||||
carbonManager.addCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
carbonManager.addCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||||
}
|
}
|
||||||
|
@ -907,7 +901,7 @@ public final class OmemoManager extends Manager {
|
||||||
* Remove active stanza listeners needed for OMEMO.
|
* Remove active stanza listeners needed for OMEMO.
|
||||||
*/
|
*/
|
||||||
public void stopStanzaAndPEPListeners() {
|
public void stopStanzaAndPEPListeners() {
|
||||||
PepManager.getInstanceFor(connection()).removePepListener(this::deviceListUpdateListener);
|
pepManager.removePepEventListener(pepOmemoDeviceListEventListener);
|
||||||
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
connection().removeAsyncStanzaListener(this::internalOmemoMessageStanzaListener);
|
||||||
CarbonManager.getInstanceFor(connection()).removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
CarbonManager.getInstanceFor(connection()).removeCarbonCopyReceivedListener(this::internalOmemoCarbonCopyListener);
|
||||||
}
|
}
|
||||||
|
@ -992,41 +986,17 @@ public final class OmemoManager extends Manager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@SuppressWarnings("UnnecessaryLambda")
|
||||||
* PEPListener that listens for OMEMO deviceList updates.
|
private final PepEventListener<OmemoDeviceListElement> pepOmemoDeviceListEventListener =
|
||||||
*/
|
(from, receivedDeviceList, id, message) -> {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Device List <list>
|
// Device List <list>
|
||||||
OmemoCachedDeviceList deviceList;
|
OmemoCachedDeviceList deviceList;
|
||||||
OmemoDeviceListElement receivedDeviceList = (OmemoDeviceListElement) payloadItem.getPayload();
|
|
||||||
try {
|
try {
|
||||||
getOmemoService().getOmemoStoreBackend().mergeCachedDeviceList(getOwnDevice(), from,
|
getOmemoService().getOmemoStoreBackend().mergeCachedDeviceList(getOwnDevice(), from,
|
||||||
receivedDeviceList);
|
receivedDeviceList);
|
||||||
|
|
||||||
if (!from.asBareJid().equals(getOwnJid())) {
|
if (!from.asBareJid().equals(getOwnJid())) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceList = getOmemoService().cleanUpDeviceList(getOwnDevice());
|
deviceList = getOmemoService().cleanUpDeviceList(getOwnDevice());
|
||||||
|
@ -1034,7 +1004,7 @@ public final class OmemoManager extends Manager {
|
||||||
LOGGER.log(Level.SEVERE,
|
LOGGER.log(Level.SEVERE,
|
||||||
"IOException while processing OMEMO PEP device updates. Message: " + message,
|
"IOException while processing OMEMO PEP device updates. Message: " + message,
|
||||||
e);
|
e);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
final OmemoDeviceListElement_VAxolotl newDeviceList = new OmemoDeviceListElement_VAxolotl(deviceList);
|
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.
|
* StanzaFilter that filters messages containing a OMEMO element.
|
||||||
|
|
|
@ -31,7 +31,6 @@ public final class OmemoConstants {
|
||||||
|
|
||||||
// PubSub Node names
|
// PubSub Node names
|
||||||
public static final String PEP_NODE_DEVICE_LIST = OMEMO_NAMESPACE_V_AXOLOTL + ".devicelist";
|
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";
|
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.store.definition.OpenPgpTrustStore;
|
||||||
import org.jivesoftware.smackx.ox.util.OpenPgpPubSubUtil;
|
import org.jivesoftware.smackx.ox.util.OpenPgpPubSubUtil;
|
||||||
import org.jivesoftware.smackx.ox.util.SecretKeyBackupHelper;
|
import org.jivesoftware.smackx.ox.util.SecretKeyBackupHelper;
|
||||||
|
import org.jivesoftware.smackx.pep.PepEventListener;
|
||||||
import org.jivesoftware.smackx.pep.PepListener;
|
import org.jivesoftware.smackx.pep.PepListener;
|
||||||
import org.jivesoftware.smackx.pep.PepManager;
|
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.LeafNode;
|
||||||
import org.jivesoftware.smackx.pubsub.PayloadItem;
|
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubException;
|
import org.jivesoftware.smackx.pubsub.PubSubException;
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubFeature;
|
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<SignElementReceivedListener> signElementReceivedListeners = new HashSet<>();
|
||||||
private final Set<CryptElementReceivedListener> cryptElementReceivedListeners = 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}.
|
* 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);
|
publishPublicKey(pepManager, pubkeyElement, primaryFingerprint);
|
||||||
|
|
||||||
// Subscribe to public key changes
|
// Subscribe to public key changes
|
||||||
PepManager.getInstanceFor(connection()).addPepListener(this::metadataListener);
|
pepManager.addPepEventListener(PEP_NODE_PUBLIC_KEYS, PublicKeysListElement.class, pepPublicKeyListElementListener);
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection())
|
ServiceDiscoveryManager.getInstanceFor(connection())
|
||||||
.addFeature(PEP_NODE_PUBLIC_KEYS_NOTIFY);
|
.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.
|
* Remove the metadata listener. This method is mainly used in tests.
|
||||||
*/
|
*/
|
||||||
public void stopMetadataListener() {
|
public void stopMetadataListener() {
|
||||||
PepManager.getInstanceFor(connection()).removePepListener(this::metadataListener);
|
pepManager.removePepEventListener(pepPublicKeyListElementListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -496,26 +497,6 @@ public final class OpenPgpManager extends Manager {
|
||||||
Private stuff.
|
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) {
|
private void processPublicKeysListElement(BareJid contact, PublicKeysListElement listElement) {
|
||||||
OpenPgpContact openPgpContact = getOpenPgpContact(contact.asEntityBareJidIfPossible());
|
OpenPgpContact openPgpContact = getOpenPgpContact(contact.asEntityBareJidIfPossible());
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue