diff --git a/js/background.js b/js/background.js index 0e228228a..948bc1283 100644 --- a/js/background.js +++ b/js/background.js @@ -1264,7 +1264,6 @@ unidentifiedDeliveryReceived: data.unidentifiedDeliveryReceived, type: 'incoming', unread: 1, - preKeyBundle: data.preKeyBundle || null, }; if (data.type === 'friend-request') { diff --git a/js/modules/data.js b/js/modules/data.js index a31ed1c74..5e61d5a43 100644 --- a/js/modules/data.js +++ b/js/modules/data.js @@ -727,7 +727,6 @@ async function searchConversations(query, { ConversationCollection }) { } // Message -const MESSAGE_PRE_KEYS = ['identityKey', 'preKey', 'signature', 'signedKey'].map(k => `preKeyBundle.${k}`); async function getMessageCount() { return channels.getMessageCount(); } @@ -745,8 +744,7 @@ async function saveSeenMessageHash(data) { } async function saveMessage(data, { forceSave, Message } = {}) { - const updated = keysFromArrayBuffer(MESSAGE_PRE_KEYS, data); - const id = await channels.saveMessage(_cleanData(updated), { forceSave }); + const id = await channels.saveMessage(_cleanData(data), { forceSave }); Message.refreshExpirationTimer(); return id; } @@ -789,8 +787,7 @@ async function saveLegacyMessage(data) { } async function saveMessages(arrayOfMessages, { forceSave } = {}) { - const updated = arrayOfMessages.map(m => keysFromArrayBuffer(MESSAGE_PRE_KEYS, m)); - await channels.saveMessages(_cleanData(updated), { forceSave }); + await channels.saveMessages(_cleanData(arrayOfMessages), { forceSave }); } async function removeMessage(id, { Message }) { diff --git a/libloki/libloki-protocol.js b/libloki/libloki-protocol.js index 204a36c9c..1dafb1f78 100644 --- a/libloki/libloki-protocol.js +++ b/libloki/libloki-protocol.js @@ -98,47 +98,26 @@ signedKey, signature, }) { - const signedKeyPromise = new Promise(async resolve => { - const existingSignedKeys = await textsecure.storage.protocol.loadContactSignedPreKeys( - { identityKeyString: pubKey, keyId: signedKeyId } - ); - if ( - !existingSignedKeys || - (existingSignedKeys instanceof Array && existingSignedKeys.length === 0) - ) { - const signedPreKey = { - keyId: signedKeyId, - publicKey: signedKey, - signature, - }; - await textsecure.storage.protocol.storeContactSignedPreKey( - pubKey, - signedPreKey - ); - } - resolve(); - }); + const signedPreKey = { + keyId: signedKeyId, + publicKey: signedKey, + signature, + }; - const preKeyPromise = new Promise(async resolve => { - const existingPreKeys = await textsecure.storage.protocol.loadContactPreKeys({ - identityKeyString: pubKey, - keyId: preKeyId, - }); - if ( - !existingPreKeys || - (existingPreKeys instanceof Array && existingPreKeys.length === 0) - ) { - const preKeyObject = { - publicKey: preKey, - keyId: preKeyId, - }; - await textsecure.storage.protocol.storeContactPreKey( - pubKey, - preKeyObject - ); - } - resolve(); - }); + const signedKeyPromise = textsecure.storage.protocol.storeContactSignedPreKey( + pubKey, + signedPreKey + ); + + const preKeyObject = { + publicKey: preKey, + keyId: preKeyId, + }; + + const preKeyPromise = textsecure.storage.protocol.storeContactPreKey( + pubKey, + preKeyObject + ); await Promise.all([signedKeyPromise, preKeyPromise]); } diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 28b3ad11c..fbb7ab54f 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -721,15 +721,11 @@ MessageReceiver.prototype.extend({ // eslint-disable-next-line no-param-reassign envelope.preKeyBundleMessage = decodedBundle; - // Save the preKey bundle if this is not a friend request. - // 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 - ); - } + // Save the preKeyBundle + await this.handlePreKeyBundleMessage( + envelope.source, + envelope.preKeyBundleMessage + ); } const me = { @@ -970,7 +966,6 @@ MessageReceiver.prototype.extend({ receivedAt: envelope.receivedAt, unidentifiedDeliveryReceived: envelope.unidentifiedDeliveryReceived, message, - preKeyBundle: envelope.preKeyBundleMessage || null, }; return this.dispatchAndWait(ev); }) @@ -1010,15 +1005,8 @@ MessageReceiver.prototype.extend({ await conversation.updateTextInputState(); } - // If we accepted an incoming friend request then save the preKeyBundle + // If we accepted an incoming friend request then update our state if (message.direction === 'incoming' && message.friendStatus === 'accepted') { - // Register the preKeys used for communication - if (message.preKeyBundle) { - await this.handlePreKeyBundleMessage( - pubKey, - message.preKeyBundle - ); - } // Accept the friend request if (conversation) { @@ -1028,6 +1016,9 @@ MessageReceiver.prototype.extend({ // Send a reply back libloki.sendFriendRequestAccepted(pubKey); } + + // TODO: If we decline a friend request then delete preKeys from our db + window.log.info(`Friend request for ${pubKey} was ${message.friendStatus}`, message); }, async innerHandleContentMessage(envelope, plaintext) {