1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-23 19:18:00 +01:00

OMEMO: Unspaghetti PEP listener code

While I like Spaghetti, I don't like them in my code.

4 insertions, 24 deletions, *kaboom*. :)
This commit is contained in:
Florian Schmaus 2017-09-29 15:36:28 +02:00
parent 941f29e928
commit 58181bab08
2 changed files with 4 additions and 24 deletions

View file

@ -19,6 +19,7 @@ package org.jivesoftware.smackx.omemo;
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.BODY_OMEMO_HINT;
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.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.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@ -132,6 +133,9 @@ public final class OmemoManager extends Manager {
}
});
PEPManager.getInstanceFor(connection).addPEPListener(deviceListUpdateListener);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(PEP_NODE_DEVICE_LIST_NOTIFY);
service = OmemoService.getInstance();
}

View file

@ -19,7 +19,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_BUNDLE_FROM_DEVICE_ID;
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.PEP_NODE_DEVICE_LIST;
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.PEP_NODE_DEVICE_LIST_NOTIFY;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
@ -55,7 +54,6 @@ import org.jivesoftware.smack.util.Async;
import org.jivesoftware.smackx.carbons.CarbonCopyReceivedListener;
import org.jivesoftware.smackx.carbons.CarbonManager;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.forward.packet.Forwarded;
import org.jivesoftware.smackx.mam.MamManager;
import org.jivesoftware.smackx.muc.MultiUserChat;
@ -79,7 +77,6 @@ import org.jivesoftware.smackx.omemo.internal.OmemoMessageInformation;
import org.jivesoftware.smackx.omemo.internal.OmemoSession;
import org.jivesoftware.smackx.omemo.util.OmemoConstants;
import org.jivesoftware.smackx.omemo.util.OmemoMessageBuilder;
import org.jivesoftware.smackx.pep.PEPManager;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubException;
@ -228,7 +225,6 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
publishDeviceIdIfNeeded(omemoManager, false, mustPublishId);
publishBundle(omemoManager);
subscribeToDeviceLists(omemoManager);
registerOmemoMessageStanzaListeners(omemoManager); //Wait for new OMEMO messages
getOmemoStoreBackend().initializeOmemoSessions(omemoManager); //Preload existing OMEMO sessions
}
@ -588,16 +584,6 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
return new OmemoDeviceListVAxolotlElement(emptySet);
}
/**
* Subscribe to the device lists of our contacts using PEP.
*
* @param omemoManager omemoManager we want to subscribe with
*/
private static void subscribeToDeviceLists(OmemoManager omemoManager) {
registerDeviceListListener(omemoManager);
ServiceDiscoveryManager.getInstanceFor(omemoManager.getConnection()).addFeature(PEP_NODE_DEVICE_LIST_NOTIFY);
}
/**
* Build sessions for all devices of the contact that we do not have a session with yet.
*
@ -694,16 +680,6 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
*/
protected abstract void processBundle(OmemoManager omemoManager, T_Bundle bundle, OmemoDevice device) throws CorruptedOmemoKeyException;
/**
* Register a PEPListener that listens for deviceList updates.
*
* @param omemoManager omemoManager we want to register with.
*/
private static void registerDeviceListListener(final OmemoManager omemoManager) {
PEPManager.getInstanceFor(omemoManager.getConnection()).removePEPListener(omemoManager.deviceListUpdateListener);
PEPManager.getInstanceFor(omemoManager.getConnection()).addPEPListener(omemoManager.deviceListUpdateListener);
}
/**
* Process a received message. Try to decrypt it in case we are a recipient device. If we are not a recipient
* device, return null.