diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-04-08 21:05:15 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-04-08 21:05:15 +0200 |
commit | bdd23a5ff2d1d1e82a83f72c7889db33376ae50f (patch) | |
tree | 8cbbd93f54c5dab5b62aed996f1956aff855ed6d /src/main/java/de/pixart/messenger/crypto | |
parent | 9b39e693d0ea9e1917d37c8c570529ab9a6c52b7 (diff) |
offer a more convienient way to disable omemo from trust keys dialog
Diffstat (limited to 'src/main/java/de/pixart/messenger/crypto')
-rw-r--r-- | src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java | 69 |
1 files changed, 43 insertions, 26 deletions
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<Jid, Set<Integer>> deviceIds; private final Map<String, XmppAxolotlMessage> messageCache; private final FetchStatusMap fetchStatusMap; + private final Map<Jid, Boolean> fetchDeviceListStatus = new HashMap<>(); private final HashMap<Jid, List<OnDeviceIdsFetched>> 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<Jid> jids) { + for(Jid jid : jids) { + if (hasErrorFetchingDeviceList(jid)) { + return true; + } + } + return false; + } + public boolean fetchMapHasErrors(List<Jid> 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<OnDeviceIdsFetched> callbacks = fetchDeviceIdsMap.remove(jid); - if (packet.getType() == IqPacket.TYPE.RESULT) { - Element item = mXmppConnectionService.getIqParser().getItem(packet); - Set<Integer> 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<OnDeviceIdsFetched> callbacks1 = fetchDeviceIdsMap.remove(jid); + if (response.getType() == IqPacket.TYPE.RESULT) { + fetchDeviceListStatus.put(jid, true); + Element item = mXmppConnectionService.getIqParser().getItem(response); + Set<Integer> 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<Jid> unfinishedJids = new ArrayList<>(jids); synchronized (unfinishedJids) { for (Jid jid : unfinishedJids) { - fetchDeviceIds(jid, new OnDeviceIdsFetched() { - @Override - public void fetched(Jid jid, Set<Integer> 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(); } } }); |