When incoming message should've been sealed sender, reply with profile key

This commit is contained in:
Evan Hahn
2021-05-05 11:39:16 -05:00
committed by GitHub
parent 18c86898d1
commit 8ef14e6f39
10 changed files with 384 additions and 38 deletions

View File

@@ -16,6 +16,8 @@ import { createBatcher } from './util/batcher';
import { updateConversationsWithUuidLookup } from './updateConversationsWithUuidLookup';
import { initializeAllJobQueues } from './jobs/initializeAllJobQueues';
import { removeStorageKeyJobQueue } from './jobs/removeStorageKeyJobQueue';
import { ourProfileKeyService } from './services/ourProfileKey';
import { shouldRespondWithProfileKey } from './util/shouldRespondWithProfileKey';
const MAX_ATTACHMENT_DOWNLOAD_AGE = 3600 * 72 * 1000;
@@ -35,6 +37,8 @@ export async function startApp(): Promise<void> {
initializeAllJobQueues();
ourProfileKeyService.initialize(window.storage);
let resolveOnAppView: (() => void) | undefined;
const onAppView = new Promise<void>(resolve => {
resolveOnAppView = resolve;
@@ -56,6 +60,10 @@ export async function startApp(): Promise<void> {
concurrency: 1,
timeout: 1000 * 60 * 2,
});
const profileKeyResponseQueue = new window.PQueue();
profileKeyResponseQueue.pause();
window.Whisper.deliveryReceiptQueue = new window.PQueue({
concurrency: 1,
timeout: 1000 * 60 * 2,
@@ -1790,8 +1798,10 @@ export async function startApp(): Promise<void> {
connectCount += 1;
window.Whisper.deliveryReceiptQueue.pause(); // avoid flood of delivery receipts until we catch up
window.Whisper.Notifications.disable(); // avoid notification flood until empty
// To avoid a flood of operations before we catch up, we pause some queues.
profileKeyResponseQueue.pause();
window.Whisper.deliveryReceiptQueue.pause();
window.Whisper.Notifications.disable();
// initialize the socket and start listening for messages
window.log.info('Initializing socket and listening for messages');
@@ -2112,6 +2122,7 @@ export async function startApp(): Promise<void> {
newVersion
);
profileKeyResponseQueue.start();
window.Whisper.deliveryReceiptQueue.start();
window.Whisper.Notifications.enable();
@@ -2183,6 +2194,7 @@ export async function startApp(): Promise<void> {
// scenarios where we're coming back from sleep, we can get offline/online events
// very fast, and it looks like a network blip. But we need to suppress
// notifications in these scenarios too. So we listen for 'reconnect' events.
profileKeyResponseQueue.pause();
window.Whisper.deliveryReceiptQueue.pause();
window.Whisper.Notifications.disable();
}
@@ -2366,7 +2378,7 @@ export async function startApp(): Promise<void> {
// special case for syncing details about ourselves
if (details.profileKey) {
window.log.info('Got sync message with our own profile key');
window.storage.put('profileKey', details.profileKey);
ourProfileKeyService.set(details.profileKey);
}
}
@@ -2619,6 +2631,24 @@ export async function startApp(): Promise<void> {
const message = initIncomingMessage(data, messageDescriptor);
// We don't need this to interrupt our processing of the message, so we "fire and
// forget".
(async () => {
if (await shouldRespondWithProfileKey(message)) {
const contact = message.getContact();
if (!contact) {
assert(false, 'Expected message to have a contact');
return;
}
profileKeyResponseQueue.add(() => {
contact.queueJob(() => contact.sendProfileKeyUpdate());
});
}
})().catch(err => {
window.log.error(err);
});
if (data.message.reaction) {
window.normalizeUuids(
data.message.reaction,