diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index fc623312a6..fe7e5b971a 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -317,10 +317,12 @@ export async function sendToGroupViaSenderKey(options: { createdAtDate, } = attributes.senderKeyInfo; + const memberSet = new Set(conversation.getMembers()); + // 4. Partition devices into sender key and non-sender key groups const [devicesForSenderKey, devicesForNormalSend] = partition( currentDevices, - device => isValidSenderKeyRecipient(conversation, device.identifier) + device => isValidSenderKeyRecipient(memberSet, device.identifier) ); const senderKeyRecipients = getUuidsFromDevices(devicesForSenderKey); @@ -864,16 +866,9 @@ async function encryptForSenderKey({ } function isValidSenderKeyRecipient( - conversation: ConversationModel, + members: Set, uuid: string ): boolean { - if (!conversation.hasMember(uuid)) { - window.log.info( - `isValidSenderKeyRecipient: Sending to ${uuid}, not a group member` - ); - return false; - } - const memberConversation = window.ConversationController.get(uuid); if (!memberConversation) { window.log.warn( @@ -882,6 +877,13 @@ function isValidSenderKeyRecipient( return false; } + if (!members.has(memberConversation)) { + window.log.info( + `isValidSenderKeyRecipient: Sending to ${uuid}, not a group member` + ); + return false; + } + const capabilities = memberConversation.get('capabilities'); if (!capabilities?.senderKey) { return false;