Handle pkb friend request accept.

This commit is contained in:
Mikunj 2018-11-22 15:27:34 +11:00
parent 4bb93e6e3c
commit 05f8a1c43a

View file

@ -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();
}
}