From 784e5d5eee7a8edd9ba3caadbf0113b80d8ab5bc Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 17 Aug 2021 08:45:57 -0700 Subject: [PATCH] Sort sender key devices for future optimization --- ts/util/sendToGroup.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index bd7ffab10a..b6c832bf17 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -841,9 +841,20 @@ async function encryptForSenderKey({ groupIdBuffer ); - const recipients = devices.map(device => - ProtocolAddress.new(device.identifier, device.id) - ); + const recipients = devices + .slice() + .sort((a, b): number => { + if (a.identifier === b.identifier) { + return 0; + } + + if (a.identifier < b.identifier) { + return -1; + } + + return 1; + }) + .map(device => ProtocolAddress.new(device.identifier, device.id)); const identityKeyStore = new IdentityKeys(); const sessionStore = new Sessions(); return sealedSenderMultiRecipientEncrypt(