From 96fa96f5c190901fd6b9c076f62d1aaf19941037 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 6 Nov 2019 16:08:20 +1100 Subject: [PATCH] Fix sync message sending. --- .../securesms/loki/MultiDeviceUtilities.kt | 9 ------- .../securesms/sms/MessageSender.java | 24 ++++++------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt index 7ea362e844..f412564805 100644 --- a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt @@ -127,15 +127,6 @@ fun signAndSendPairingAuthorisationMessage(context: Context, pairingAuthorisatio } -fun shouldSendSycMessage(context: Context, address: Address): Promise { - if (address.isGroup || address.isEmail || address.isMmsGroup) { - return Promise.of(false) - } - - // Don't send sync messages if it's one of our devices - return isOneOfOurDevices(context, address).map { !it } -} - fun isOneOfOurDevices(context: Context, address: Address): Promise { if (address.isGroup || address.isEmail || address.isMmsGroup) { return Promise.of(false) diff --git a/src/org/thoughtcrime/securesms/sms/MessageSender.java b/src/org/thoughtcrime/securesms/sms/MessageSender.java index b0f77a6fe3..242a7722d8 100644 --- a/src/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/src/org/thoughtcrime/securesms/sms/MessageSender.java @@ -288,6 +288,7 @@ public class MessageSender { return; } + // If we get here then we are sending a message to a device that is not ours boolean[] hasSentSyncMessage = { false }; MultiDeviceUtilities.getAllDevicePublicKeysWithFriendStatus(context, recipientPublicKey).success(devices -> { int friendCount = MultiDeviceUtilities.getFriendCount(context, devices.keySet()); @@ -302,24 +303,13 @@ public class MessageSender { if (isFriend) { // Send a normal message if the user is friends with the recipient // We should also send a sync message if we haven't already sent one - Promise promise = Promise.Companion.of(false, Kovenant.INSTANCE.getContext()); - if (!hasSentSyncMessage[0]) { - promise = MultiDeviceUtilities.shouldSendSycMessage(context, address).success(value -> { - hasSentSyncMessage[0] = value; - return Unit.INSTANCE; - }); + boolean shouldSendSyncMessage = !hasSentSyncMessage[0] && address.isPhone(); + if (type == MessageType.MEDIA) { + PushMediaSendJob.enqueue(context, jobManager, messageId, messageIDToUse, address, shouldSendSyncMessage); + } else { + jobManager.add(new PushTextSendJob(messageId, messageIDToUse, address, shouldSendSyncMessage)); } - - promise.success(shouldSendSyncMessage -> { - Util.runOnMain(() -> { - if (type == MessageType.MEDIA) { - PushMediaSendJob.enqueue(context, jobManager, messageId, messageIDToUse, address, shouldSendSyncMessage); - } else { - jobManager.add(new PushTextSendJob(messageId, messageIDToUse, address, shouldSendSyncMessage)); - } - }); - return Unit.INSTANCE; - }); + if (shouldSendSyncMessage) { hasSentSyncMessage[0] = true; } } else { // Send friend requests to non friends. If the user is friends with any // of the devices then send out a default friend request message.