mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Fix fetchDeviceList bug, async listeners
This commit is contained in:
parent
a10bab80cb
commit
c287345ce7
2 changed files with 82 additions and 21 deletions
|
@ -133,7 +133,7 @@ public final class OmemoManager extends Manager {
|
||||||
service.registerRatchetForManager(this);
|
service.registerRatchetForManager(this);
|
||||||
|
|
||||||
// StanzaListeners
|
// StanzaListeners
|
||||||
startStanzaListeners();
|
resumeStanzaListeners();
|
||||||
|
|
||||||
// Announce OMEMO support
|
// Announce OMEMO support
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(PEP_NODE_DEVICE_LIST_NOTIFY);
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(PEP_NODE_DEVICE_LIST_NOTIFY);
|
||||||
|
@ -647,6 +647,24 @@ public final class OmemoManager extends Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish a new device list with just our own deviceId in it.
|
||||||
|
*
|
||||||
|
* @throws SmackException.NotLoggedInException
|
||||||
|
* @throws InterruptedException
|
||||||
|
* @throws XMPPException.XMPPErrorException
|
||||||
|
* @throws SmackException.NotConnectedException
|
||||||
|
* @throws SmackException.NoResponseException
|
||||||
|
*/
|
||||||
|
public void purgeDeviceList()
|
||||||
|
throws SmackException.NotLoggedInException, InterruptedException, XMPPException.XMPPErrorException,
|
||||||
|
SmackException.NotConnectedException, SmackException.NoResponseException
|
||||||
|
{
|
||||||
|
synchronized (LOCK) {
|
||||||
|
getOmemoService().purgeDeviceList(new LoggedInOmemoManager(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate the signedPreKey published in our OmemoBundle and republish it. This should be done every now and
|
* Rotate the signedPreKey published in our OmemoBundle and republish it. This should be done every now and
|
||||||
* then (7-14 days). The old signedPreKey should be kept for some more time (a month or so) to enable decryption
|
* then (7-14 days). The old signedPreKey should be kept for some more time (a month or so) to enable decryption
|
||||||
|
@ -682,7 +700,7 @@ public final class OmemoManager extends Manager {
|
||||||
* @param stanza stanza
|
* @param stanza stanza
|
||||||
* @return true if stanza has extension 'encrypted'
|
* @return true if stanza has extension 'encrypted'
|
||||||
*/
|
*/
|
||||||
public static boolean stanzaContainsOmemoElement(Stanza stanza) {
|
static boolean stanzaContainsOmemoElement(Stanza stanza) {
|
||||||
return stanza.hasExtension(OmemoElement.NAME_ENCRYPTED, OMEMO_NAMESPACE_V_AXOLOTL);
|
return stanza.hasExtension(OmemoElement.NAME_ENCRYPTED, OMEMO_NAMESPACE_V_AXOLOTL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,7 +837,7 @@ public final class OmemoManager extends Manager {
|
||||||
* This method is called automatically in the constructor and should only be used to restore the previous state
|
* This method is called automatically in the constructor and should only be used to restore the previous state
|
||||||
* after {@link #stopListeners()} was called.
|
* after {@link #stopListeners()} was called.
|
||||||
*/
|
*/
|
||||||
public void startStanzaListeners() {
|
public void resumeStanzaListeners() {
|
||||||
PEPManager pepManager = PEPManager.getInstanceFor(connection());
|
PEPManager pepManager = PEPManager.getInstanceFor(connection());
|
||||||
CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());
|
CarbonManager carbonManager = CarbonManager.getInstanceFor(connection());
|
||||||
|
|
||||||
|
@ -866,8 +884,12 @@ public final class OmemoManager extends Manager {
|
||||||
* StanzaListener that listens for incoming Stanzas which contain OMEMO elements.
|
* StanzaListener that listens for incoming Stanzas which contain OMEMO elements.
|
||||||
*/
|
*/
|
||||||
private final StanzaListener internalOmemoMessageStanzaListener = new StanzaListener() {
|
private final StanzaListener internalOmemoMessageStanzaListener = new StanzaListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
|
public void processStanza(final Stanza packet) {
|
||||||
|
Async.go(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
getOmemoService().onOmemoMessageStanzaReceived(packet,
|
getOmemoService().onOmemoMessageStanzaReceived(packet,
|
||||||
new LoggedInOmemoManager(OmemoManager.this));
|
new LoggedInOmemoManager(OmemoManager.this));
|
||||||
|
@ -875,6 +897,8 @@ public final class OmemoManager extends Manager {
|
||||||
LOGGER.warning("Received OMEMO stanza while being offline: " + e);
|
LOGGER.warning("Received OMEMO stanza while being offline: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -882,9 +906,12 @@ public final class OmemoManager extends Manager {
|
||||||
*/
|
*/
|
||||||
private final CarbonCopyReceivedListener internalOmemoCarbonCopyListener = new CarbonCopyReceivedListener() {
|
private final CarbonCopyReceivedListener internalOmemoCarbonCopyListener = new CarbonCopyReceivedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCarbonCopyReceived(CarbonExtension.Direction direction,
|
public void onCarbonCopyReceived(final CarbonExtension.Direction direction,
|
||||||
Message carbonCopy,
|
final Message carbonCopy,
|
||||||
Message wrappingMessage) {
|
final Message wrappingMessage) {
|
||||||
|
Async.go(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (omemoMessageStanzaFilter.accept(carbonCopy)) {
|
if (omemoMessageStanzaFilter.accept(carbonCopy)) {
|
||||||
try {
|
try {
|
||||||
getOmemoService().onOmemoCarbonCopyReceived(direction, carbonCopy, wrappingMessage,
|
getOmemoService().onOmemoCarbonCopyReceived(direction, carbonCopy, wrappingMessage,
|
||||||
|
@ -894,6 +921,8 @@ public final class OmemoManager extends Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -704,7 +704,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
||||||
// refreshOmemoDeviceList;
|
// refreshOmemoDeviceList;
|
||||||
OmemoDeviceListElement publishedList;
|
OmemoDeviceListElement publishedList;
|
||||||
try {
|
try {
|
||||||
publishedList = fetchDeviceList(connection, userDevice.getJid());
|
publishedList = fetchDeviceList(connection, contact);
|
||||||
} catch (PubSubException.NotAPubSubNodeException e) {
|
} catch (PubSubException.NotAPubSubNodeException e) {
|
||||||
LOGGER.log(Level.WARNING, "Error refreshing deviceList: ", e);
|
LOGGER.log(Level.WARNING, "Error refreshing deviceList: ", e);
|
||||||
publishedList = null;
|
publishedList = null;
|
||||||
|
@ -1137,4 +1137,36 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish a new DeviceList with just our device in it.
|
||||||
|
*
|
||||||
|
* @param managerGuard authenticated OmemoManager.
|
||||||
|
* @throws InterruptedException
|
||||||
|
* @throws XMPPException.XMPPErrorException
|
||||||
|
* @throws SmackException.NotConnectedException
|
||||||
|
* @throws SmackException.NoResponseException
|
||||||
|
*/
|
||||||
|
public void purgeDeviceList(OmemoManager.LoggedInOmemoManager managerGuard)
|
||||||
|
throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException,
|
||||||
|
SmackException.NoResponseException
|
||||||
|
{
|
||||||
|
OmemoManager omemoManager = managerGuard.get();
|
||||||
|
OmemoDevice userDevice = omemoManager.getOwnDevice();
|
||||||
|
OmemoCachedDeviceList list = getOmemoStoreBackend().loadCachedDeviceList(userDevice);
|
||||||
|
|
||||||
|
//Mark all devices inactive
|
||||||
|
for (int i : list.getActiveDevices()) {
|
||||||
|
list.addInactiveDevice(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add back our device
|
||||||
|
list.addDevice(userDevice.getDeviceId());
|
||||||
|
|
||||||
|
OmemoDeviceListElement_VAxolotl listElement = new OmemoDeviceListElement_VAxolotl(list);
|
||||||
|
// Merge list
|
||||||
|
getOmemoStoreBackend().mergeCachedDeviceList(userDevice, userDevice.getJid(), listElement);
|
||||||
|
|
||||||
|
OmemoService.publishDeviceList(omemoManager.getConnection(), listElement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue