Speed-up senderKey membership check

This commit is contained in:
Fedor Indutny 2021-08-19 08:52:08 -07:00 committed by GitHub
parent aecb11247f
commit 65f0f87bad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -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<ConversationModel>,
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;