Remove preKeyBundle from message.

Always save preKeyBundles if we receive them.
Always override preKeys when saving.
pull/54/head
Mikunj 6 years ago
parent 149da3374a
commit 0dabce9e28

@ -1264,7 +1264,6 @@
unidentifiedDeliveryReceived: data.unidentifiedDeliveryReceived,
type: 'incoming',
unread: 1,
preKeyBundle: data.preKeyBundle || null,
};
if (data.type === 'friend-request') {

@ -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 }) {

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

@ -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) {

Loading…
Cancel
Save