From fb020f88ea34f97529aacec2b94ead49392818d8 Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Tue, 23 Oct 2018 15:35:44 +1100 Subject: [PATCH] call 'onFriendRequestSent' only after the message was successfully sent --- libtextsecure/outgoing_message.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 3303d7be2..1c05f848a 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -365,18 +365,22 @@ OutgoingMessage.prototype = { }, sendToNumber(number) { + let conversation; + try { + conversation = ConversationController.get(number); + } catch(e) { + } + return this.getStaleDeviceIdsForNumber(number).then(updateDevices => this.getKeysForNumber(number, updateDevices) .then(async (keysFound) => { - const conversation = ConversationController.get(number); let attachPrekeys = false; if (!keysFound) { log.info("Fallback encryption enabled"); - conversation.onFriendRequestSent(); this.fallBackEncryption = true; attachPrekeys = true; - } else { + } else if (conversation) { try { attachPrekeys = !conversation.isKeyExchangeCompleted(); } catch(e) { @@ -389,6 +393,11 @@ OutgoingMessage.prototype = { this.message.preKeyBundleMessage = await libloki.getPreKeyBundleForNumber(number); } }).then(this.reloadDevicesAndSend(number, true)) + .then(() => { + if (this.fallBackEncryption && conversation) { + conversation.onFriendRequestSent(); + } + }) .catch(error => { if (error.message === 'Identity key changed') { // eslint-disable-next-line no-param-reassign