Fix checking for when a friend request was accepted.

pull/38/head
Mikunj 7 years ago
parent 3389b1d457
commit 245ae721c7

@ -991,33 +991,24 @@ MessageReceiver.prototype.extend({
content.dataMessage.body,
content.preKeyBundleMessage,
);
}
// Exit early since the friend request reply will be a regular empty message
return;
}
// Check if our friend request got accepted
if (content.preKeyBundleMessage) {
// By default we don't want to save the preKey
let savePreKey = false;
// The conversation
let conversation = null;
try {
conversation = ConversationController.get(envelope.source);
// We only want to save the preKey if we have a outgoing friend request which is pending
} else {
const keyExchangeComplete = conversation.isKeyExchangeCompleted();
// Check here if we received preKeys from the other user
// We are certain that other user accepted the friend request IF:
// - The message has a preKeyBundleMessage
// - We have an outgoing friend request that is pending
// The second check is crucial because it makes sure we don't save the preKeys of the incoming friend request (which is saved only when we press accept)
if (!keyExchangeComplete && content.preKeyBundleMessage) {
// Check for any outgoing friend requests
const pending = await conversation.getPendingFriendRequests('outgoing');
const successful = pending.filter(p => !p.hasErrors());
// Save the key only if we have an outgoing friend request
savePreKey = (successful.length > 0);
} catch (e) {}
const savePreKey = (successful.length > 0);
// Save the pre key if we have a conversation
if (savePreKey && conversation) {
// Save the pre key
if (savePreKey) {
await this.handlePreKeyBundleMessage(
envelope.source,
this.decodePreKeyBundleMessage(content.preKeyBundleMessage),
@ -1025,10 +1016,13 @@ MessageReceiver.prototype.extend({
// Update the conversation
await conversation.onFriendRequestAccepted();
}
}
}
// Exit early since the friend request reply will be a regular empty message
return;
}
}
if (content.syncMessage) {
return this.handleSyncMessage(envelope, content.syncMessage);

Loading…
Cancel
Save