code cleanup in AxolotlService.fetchDeviceIds()

This commit is contained in:
Daniel Gultsch 2018-04-12 08:55:50 +02:00
parent aff2b33e27
commit 7fd25abea2

View file

@ -978,7 +978,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
fetchDeviceIds(jid, null); fetchDeviceIds(jid, null);
} }
public void fetchDeviceIds(final Jid jid, OnDeviceIdsFetched callback) { private void fetchDeviceIds(final Jid jid, OnDeviceIdsFetched callback) {
IqPacket packet;
synchronized (this.fetchDeviceIdsMap) { synchronized (this.fetchDeviceIdsMap) {
List<OnDeviceIdsFetched> callbacks = this.fetchDeviceIdsMap.get(jid); List<OnDeviceIdsFetched> callbacks = this.fetchDeviceIdsMap.get(jid);
if (callbacks != null) { if (callbacks != null) {
@ -986,6 +987,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
callbacks.add(callback); callbacks.add(callback);
} }
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid + " already running. adding callback"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid + " already running. adding callback");
packet = null;
} else { } else {
callbacks = new ArrayList<>(); callbacks = new ArrayList<>();
if (callback != null) { if (callback != null) {
@ -993,18 +995,21 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} }
this.fetchDeviceIdsMap.put(jid, callbacks); this.fetchDeviceIdsMap.put(jid, callbacks);
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching device ids for " + jid);
IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(jid); packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(jid);
}
}
if (packet != null) {
mXmppConnectionService.sendIqPacket(account, packet, (account, response) -> { mXmppConnectionService.sendIqPacket(account, packet, (account, response) -> {
synchronized (fetchDeviceIdsMap) { synchronized (fetchDeviceIdsMap) {
List<OnDeviceIdsFetched> callbacks1 = fetchDeviceIdsMap.remove(jid); List<OnDeviceIdsFetched> callbacks = fetchDeviceIdsMap.remove(jid);
if (response.getType() == IqPacket.TYPE.RESULT) { if (response.getType() == IqPacket.TYPE.RESULT) {
fetchDeviceListStatus.put(jid, true); fetchDeviceListStatus.put(jid, true);
Element item = mXmppConnectionService.getIqParser().getItem(response); Element item = mXmppConnectionService.getIqParser().getItem(response);
Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
registerDevices(jid, deviceIds); registerDevices(jid, deviceIds);
if (callbacks1 != null) { if (callbacks != null) {
for (OnDeviceIdsFetched callback1 : callbacks1) { for (OnDeviceIdsFetched c : callbacks) {
callback1.fetched(jid, deviceIds); c.fetched(jid, deviceIds);
} }
} }
} else { } else {
@ -1013,9 +1018,9 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} else { } else {
fetchDeviceListStatus.put(jid, false); fetchDeviceListStatus.put(jid, false);
} }
if (callbacks1 != null) { if (callbacks != null) {
for (OnDeviceIdsFetched callback1 : callbacks1) { for (OnDeviceIdsFetched c : callbacks) {
callback1.fetched(jid, null); c.fetched(jid, null);
} }
} }
} }
@ -1023,7 +1028,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}); });
} }
} }
}
private void fetchDeviceIds(List<Jid> jids, final OnMultipleDeviceIdFetched callback) { private void fetchDeviceIds(List<Jid> jids, final OnMultipleDeviceIdFetched callback) {
final ArrayList<Jid> unfinishedJids = new ArrayList<>(jids); final ArrayList<Jid> unfinishedJids = new ArrayList<>(jids);