From 05f8a1c43a1970a4de39b7136873f17c78e9957b Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 22 Nov 2018 15:27:34 +1100 Subject: [PATCH] Handle pkb friend request accept. --- libtextsecure/message_receiver.js | 34 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index dab71c94d..21a5d1102 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -725,10 +725,19 @@ MessageReceiver.prototype.extend({ // We don't automatically save on a friend request because // we only want to save the preKeys when we click the accept button. if (envelope.type !== textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { - await this.handlePreKeyBundleMessage( - envelope.source, - envelope.preKeyBundleMessage - ); + try { + const conversation = window.ConversationController.get(envelope.source); + + // Make sure we only save the preKeys if we're friends + if (conversation.isFriend()) { + await this.handlePreKeyBundleMessage( + envelope.source, + envelope.preKeyBundleMessage + ); + } + } catch (e) { + window.log.info('Error saving preKeyBundleMessage from: ', envelope.source); + } } } @@ -1040,6 +1049,15 @@ MessageReceiver.prototype.extend({ window.log.info('Error getting conversation: ', envelope.source); } + // Check if the other user accepted our friend request + if ( + envelope.preKeyBundleMessage && + envelope.preKeyBundleMessage.type === textsecure.protobuf.PreKeyBundleMessage.Type.FRIEND_REQUEST_ACCEPT && + conversation + ) { + await conversation.onFriendRequestAccepted(); + } + if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { return this.handleFriendRequestMessage(envelope, content.dataMessage); } else if ( @@ -1048,12 +1066,10 @@ MessageReceiver.prototype.extend({ // ref: libsignal-protocol.js:36120 envelope.type === textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE ) { - // We know for sure that keys are exchanged - if (conversation) { + // If we get a cipher and we're already friends + // then we set our key exchange to complete + if (conversation && conversation.isFriend()) { await conversation.setKeyExchangeCompleted(true); - - // TODO: We should probably set this based on the PKB type - await conversation.onFriendRequestAccepted(); } }