From bdd23a5ff2d1d1e82a83f72c7889db33376ae50f Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 8 Apr 2018 21:05:15 +0200 Subject: offer a more convienient way to disable omemo from trust keys dialog --- .../messenger/crypto/axolotl/AxolotlService.java | 69 ++++++++++++++-------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'src/main/java/de/pixart/messenger/crypto') diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java index 2efdb8040..d23e3a88b 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java @@ -77,6 +77,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { private final Map> deviceIds; private final Map messageCache; private final FetchStatusMap fetchStatusMap; + private final Map fetchDeviceListStatus = new HashMap<>(); private final HashMap> fetchDeviceIdsMap = new HashMap<>(); private final SerialSingleThreadExecutor executor; private int numPublishTriesOnEmptyPep = 0; @@ -97,6 +98,20 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } } + private boolean hasErrorFetchingDeviceList(Jid jid) { + Boolean status = fetchDeviceListStatus.get(jid); + return status != null && !status; + } + + public boolean hasErrorFetchingDeviceList(List jids) { + for(Jid jid : jids) { + if (hasErrorFetchingDeviceList(jid)) { + return true; + } + } + return false; + } + public boolean fetchMapHasErrors(List jids) { for (Jid jid : jids) { if (deviceIds.get(jid) != null) { @@ -361,6 +376,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { public void clearErrorsInFetchStatusMap(Jid jid) { fetchStatusMap.clearErrorFor(jid); + fetchDeviceListStatus.remove(jid); } public void regenerateKeys(boolean wipeOther) { @@ -368,6 +384,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { sessions.clear(); fetchStatusMap.clear(); fetchDeviceIdsMap.clear(); + fetchDeviceListStatus.clear(); publishBundlesIfNeeded(true, wipeOther); } @@ -960,26 +977,29 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { this.fetchDeviceIdsMap.put(jid, callbacks); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid); IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(jid); - mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, IqPacket packet) { - synchronized (fetchDeviceIdsMap) { - List callbacks = fetchDeviceIdsMap.remove(jid); - if (packet.getType() == IqPacket.TYPE.RESULT) { - Element item = mXmppConnectionService.getIqParser().getItem(packet); - Set deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); - registerDevices(jid, deviceIds); - if (callbacks != null) { - for (OnDeviceIdsFetched callback : callbacks) { - callback.fetched(jid, deviceIds); - } + mXmppConnectionService.sendIqPacket(account, packet, (account, response) -> { + synchronized (fetchDeviceIdsMap) { + List callbacks1 = fetchDeviceIdsMap.remove(jid); + if (response.getType() == IqPacket.TYPE.RESULT) { + fetchDeviceListStatus.put(jid, true); + Element item = mXmppConnectionService.getIqParser().getItem(response); + Set deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); + registerDevices(jid, deviceIds); + if (callbacks1 != null) { + for (OnDeviceIdsFetched callback1 : callbacks1) { + callback1.fetched(jid, deviceIds); } + } + } else { + if (response.getType() == IqPacket.TYPE.TIMEOUT) { + fetchDeviceListStatus.remove(jid); } else { - Log.d(Config.LOGTAG, packet.toString()); - if (callbacks != null) { - for (OnDeviceIdsFetched callback : callbacks) { - callback.fetched(jid, null); - } + fetchDeviceListStatus.put(jid, false); + } + Log.d(Config.LOGTAG, response.toString()); + if (callbacks1 != null) { + for (OnDeviceIdsFetched callback1 : callbacks1) { + callback1.fetched(jid, null); } } } @@ -993,14 +1013,11 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { final ArrayList unfinishedJids = new ArrayList<>(jids); synchronized (unfinishedJids) { for (Jid jid : unfinishedJids) { - fetchDeviceIds(jid, new OnDeviceIdsFetched() { - @Override - public void fetched(Jid jid, Set deviceIds) { - synchronized (unfinishedJids) { - unfinishedJids.remove(jid); - if (unfinishedJids.size() == 0 && callback != null) { - callback.fetched(); - } + fetchDeviceIds(jid, (j, deviceIds) -> { + synchronized (unfinishedJids) { + unfinishedJids.remove(j); + if (unfinishedJids.size() == 0 && callback != null) { + callback.fetched(); } } }); -- cgit v1.2.3