aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-08-01 12:53:14 +0200
committerChristian Schneppe <christian@pix-art.de>2017-08-01 12:53:14 +0200
commit9b7bcebdec9a43ec2a388704d35ebcb5c4b52cd3 (patch)
tree31122a12cb89b3a41a2a9324cc6f9d39087b29a5
parent6192b511f2ec1a8793e826b005ecbb7b743d5b01 (diff)
explicitly fetch device ids before building sessions in single mode conversation
-rw-r--r--src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java36
1 files changed, 36 insertions, 0 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 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<Integer> 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<Integer> 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<Integer> 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<SignalProtocolAddress> addresses = findDevicesWithoutSession(conversation);