Batch and de-duplicate profile key updates
This commit is contained in:
parent
c2a0072fa1
commit
e51260a23f
2 changed files with 35 additions and 31 deletions
|
@ -2675,6 +2675,30 @@ export async function startApp(): Promise<void> {
|
||||||
return confirm();
|
return confirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const respondWithProfileKeyBatcher = createBatcher<ConversationModel>({
|
||||||
|
name: 'respondWithProfileKeyBatcher',
|
||||||
|
processBatch(batch) {
|
||||||
|
const deduped = new Set(batch);
|
||||||
|
deduped.forEach(async sender => {
|
||||||
|
try {
|
||||||
|
if (!(await shouldRespondWithProfileKey(sender))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
window.log.error(
|
||||||
|
'respondWithProfileKeyBatcher error',
|
||||||
|
error && error.stack
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.queueJob(() => sender.sendProfileKeyUpdate());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
wait: 200,
|
||||||
|
maxSize: Infinity,
|
||||||
|
});
|
||||||
|
|
||||||
// Note: We do very little in this function, since everything in handleDataMessage is
|
// Note: We do very little in this function, since everything in handleDataMessage is
|
||||||
// inside a conversation-specific queue(). Any code here might run before an earlier
|
// inside a conversation-specific queue(). Any code here might run before an earlier
|
||||||
// message is processed in handleDataMessage().
|
// message is processed in handleDataMessage().
|
||||||
|
@ -2701,23 +2725,17 @@ export async function startApp(): Promise<void> {
|
||||||
|
|
||||||
const message = initIncomingMessage(data, messageDescriptor);
|
const message = initIncomingMessage(data, messageDescriptor);
|
||||||
|
|
||||||
// We don't need this to interrupt our processing of the message, so we "fire and
|
if (message.isIncoming() && message.get('unidentifiedDeliveryReceived')) {
|
||||||
// forget".
|
const sender = message.getContact();
|
||||||
(async () => {
|
|
||||||
if (await shouldRespondWithProfileKey(message)) {
|
|
||||||
const contact = message.getContact();
|
|
||||||
if (!contact) {
|
|
||||||
assert(false, 'Expected message to have a contact');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
profileKeyResponseQueue.add(() => {
|
if (!sender) {
|
||||||
contact.queueJob(() => contact.sendProfileKeyUpdate());
|
throw new Error('MessageModel has no sender.');
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})().catch(err => {
|
|
||||||
window.log.error(err);
|
profileKeyResponseQueue.add(() => {
|
||||||
});
|
respondWithProfileKeyBatcher.add(sender);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (data.message.reaction) {
|
if (data.message.reaction) {
|
||||||
window.normalizeUuids(
|
window.normalizeUuids(
|
||||||
|
|
|
@ -1,25 +1,11 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { MessageModel } from '../models/messages';
|
import { ConversationModel } from '../models/conversations';
|
||||||
import { assert } from './assert';
|
|
||||||
|
|
||||||
export async function shouldRespondWithProfileKey(
|
export async function shouldRespondWithProfileKey(
|
||||||
message: MessageModel
|
sender: ConversationModel
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (!message.isIncoming() || message.get('unidentifiedDeliveryReceived')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sender = message.getContact();
|
|
||||||
if (!sender) {
|
|
||||||
assert(
|
|
||||||
false,
|
|
||||||
'MessageModel#shouldRespondWithProfileKey had no sender. Returning false'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender.isMe() || !sender.getAccepted() || sender.isBlocked()) {
|
if (sender.isMe() || !sender.getAccepted() || sender.isBlocked()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue