From 8c91aa04f1366aaec4a1029ce5c92df2c348ad38 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 11 Mar 2020 13:18:35 +1100 Subject: [PATCH] Speed up message creation. We were fetching all of our devices everytime a new message was received. This was only used for when the message was a public chat message, so i moved it into the relevant if statement. In the future if we increase the device link limit, we'll need to fetch all our devices on application launch or something. --- js/background.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/js/background.js b/js/background.js index 2d7494b1e..105e8e71f 100644 --- a/js/background.js +++ b/js/background.js @@ -1964,21 +1964,23 @@ return handleProfileUpdate({ data, confirm, messageDescriptor }); } - const primaryDeviceKey = window.storage.get('primaryDevicePubKey'); - const allOurDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( - primaryDeviceKey - ); const descriptorId = await textsecure.MessageReceiver.arrayBufferToString( messageDescriptor.id ); let message; if ( messageDescriptor.type === 'group' && - descriptorId.match(/^publicChat:/) && - allOurDevices.includes(data.source) + descriptorId.match(/^publicChat:/) ) { - // Public chat messages from ourselves should be outgoing - message = await createSentMessage(data); + // Note: This only works currently because we have a 1 device limit + // When we change that, the check below needs to change too + const ourNumber = textsecure.storage.user.getNumber(); + const primaryDevice = window.storage.get('primaryDevicePubKey'); + const { source } = data; + if (source && (source === ourNumber || source === primaryDevice)) { + // Public chat messages from ourselves should be outgoing + message = await createSentMessage(data); + } } else { message = await createMessage(data); }