call 'onFriendRequestSent' only after the message was successfully sent

pull/17/head
sachaaaaa 7 years ago
parent 5602f4bfff
commit fb020f88ea

@ -365,18 +365,22 @@ OutgoingMessage.prototype = {
}, },
sendToNumber(number) { sendToNumber(number) {
let conversation;
try {
conversation = ConversationController.get(number);
} catch(e) {
}
return this.getStaleDeviceIdsForNumber(number).then(updateDevices => return this.getStaleDeviceIdsForNumber(number).then(updateDevices =>
this.getKeysForNumber(number, updateDevices) this.getKeysForNumber(number, updateDevices)
.then(async (keysFound) => { .then(async (keysFound) => {
const conversation = ConversationController.get(number);
let attachPrekeys = false; let attachPrekeys = false;
if (!keysFound) if (!keysFound)
{ {
log.info("Fallback encryption enabled"); log.info("Fallback encryption enabled");
conversation.onFriendRequestSent();
this.fallBackEncryption = true; this.fallBackEncryption = true;
attachPrekeys = true; attachPrekeys = true;
} else { } else if (conversation) {
try { try {
attachPrekeys = !conversation.isKeyExchangeCompleted(); attachPrekeys = !conversation.isKeyExchangeCompleted();
} catch(e) { } catch(e) {
@ -389,6 +393,11 @@ OutgoingMessage.prototype = {
this.message.preKeyBundleMessage = await libloki.getPreKeyBundleForNumber(number); this.message.preKeyBundleMessage = await libloki.getPreKeyBundleForNumber(number);
} }
}).then(this.reloadDevicesAndSend(number, true)) }).then(this.reloadDevicesAndSend(number, true))
.then(() => {
if (this.fallBackEncryption && conversation) {
conversation.onFriendRequestSent();
}
})
.catch(error => { .catch(error => {
if (error.message === 'Identity key changed') { if (error.message === 'Identity key changed') {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign

Loading…
Cancel
Save