aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/crypto/axolotl
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-24 21:52:01 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-24 21:52:01 +0200
commite6b210030da617f264fda02aacb51242db03be56 (patch)
treed3e4b55584f0d72ff987e6d2898738d0861ec6b3 /src/main/java/de/pixart/messenger/crypto/axolotl
parent2a1374a008970895a2b68c778ba2a05903798fa6 (diff)
code cleanup in AxolotlService.fetchDeviceIds()
Diffstat (limited to 'src/main/java/de/pixart/messenger/crypto/axolotl')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java54
1 files changed, 29 insertions, 25 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 010dbbceb..0cc823ba3 100644
--- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
@@ -978,7 +978,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
fetchDeviceIds(jid, null);
}
- public void fetchDeviceIds(final Jid jid, OnDeviceIdsFetched callback) {
+ private void fetchDeviceIds(final Jid jid, OnDeviceIdsFetched callback) {
+ IqPacket packet;
synchronized (this.fetchDeviceIdsMap) {
List<OnDeviceIdsFetched> callbacks = this.fetchDeviceIdsMap.get(jid);
if (callbacks != null) {
@@ -986,6 +987,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
callbacks.add(callback);
}
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid + " already running. adding callback");
+ packet = null;
} else {
callbacks = new ArrayList<>();
if (callback != null) {
@@ -993,35 +995,37 @@ 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, (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);
- }
+ packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(jid);
+ }
+ }
+ if (packet != null) {
+ mXmppConnectionService.sendIqPacket(account, packet, (account, response) -> {
+ synchronized (fetchDeviceIdsMap) {
+ List<OnDeviceIdsFetched> callbacks = 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 (callbacks != null) {
+ for (OnDeviceIdsFetched c : callbacks) {
+ c.fetched(jid, deviceIds);
}
+ }
+ } else {
+ if (response.getType() == IqPacket.TYPE.TIMEOUT) {
+ fetchDeviceListStatus.remove(jid);
} else {
- if (response.getType() == IqPacket.TYPE.TIMEOUT) {
- fetchDeviceListStatus.remove(jid);
- } else {
- fetchDeviceListStatus.put(jid, false);
- }
- if (callbacks1 != null) {
- for (OnDeviceIdsFetched callback1 : callbacks1) {
- callback1.fetched(jid, null);
- }
+ fetchDeviceListStatus.put(jid, false);
+ }
+ if (callbacks != null) {
+ for (OnDeviceIdsFetched c : callbacks) {
+ c.fetched(jid, null);
}
}
}
- });
- }
+ }
+ });
}
}