From 9b7bcebdec9a43ec2a388704d35ebcb5c4b52cd3 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 1 Aug 2017 12:53:14 +0200 Subject: explicitly fetch device ids before building sessions in single mode conversation --- .../messenger/crypto/axolotl/AxolotlService.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/main/java/de') 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 15cc71c4f..addfbf2ac 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java @@ -861,7 +861,15 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { return !hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty()); } + public interface OnDeviceIdsFetched { + void fetched(Set deviceIds); + } + public void fetchDeviceIds(final Jid jid) { + fetchDeviceIds(jid, null); + } + + public void fetchDeviceIds(final Jid jid, final OnDeviceIdsFetched callback) { Log.d(Config.LOGTAG, "fetching device ids for " + jid); IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(jid); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @@ -871,8 +879,14 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Element item = mXmppConnectionService.getIqParser().getItem(packet); Set deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); registerDevices(jid, deviceIds); + if (callback != null) { + callback.fetched(deviceIds); + } } else { Log.d(Config.LOGTAG, packet.toString()); + if (callback != null) { + callback.fetched(null); + } } } }); @@ -1009,6 +1023,28 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } public boolean createSessionsIfNeeded(final Conversation conversation) { + final Jid jid = conversation.getJid().toBareJid(); + if (conversation.getMode() == Conversation.MODE_SINGLE && hasEmptyDeviceList(jid)) { + final SignalProtocolAddress placeholder = new SignalProtocolAddress(jid.toPreppedString(), Integer.MIN_VALUE); + FetchStatus status = fetchStatusMap.get(placeholder); + if (status == null || status == FetchStatus.TIMEOUT) { + fetchStatusMap.put(placeholder, FetchStatus.PENDING); + } + fetchDeviceIds(conversation.getJid().toBareJid(), new OnDeviceIdsFetched() { + @Override + public void fetched(Set deviceIds) { + createSessionsIfNeededActual(conversation); + fetchStatusMap.put(placeholder, deviceIds != null && !deviceIds.isEmpty() ? FetchStatus.SUCCESS : FetchStatus.ERROR); + finishBuildingSessionsFromPEP(placeholder); + } + }); + return true; + } else { + return createSessionsIfNeededActual(conversation); + } + } + + private boolean createSessionsIfNeededActual(final Conversation conversation) { Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Creating axolotl sessions if needed..."); boolean newSessions = false; Set addresses = findDevicesWithoutSession(conversation); -- cgit v1.2.3