MessageReceiver: Emit envelope event on queue for cached+decrypted items

This commit is contained in:
Scott Nonnenberg 2023-07-05 16:16:17 -07:00 committed by GitHub
parent 3bf8adf6e1
commit 8177a4e2b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 13 deletions

View file

@ -83,7 +83,8 @@ import type {
ConfigurationEvent,
DecryptionErrorEvent,
DeliveryEvent,
EnvelopeEvent,
EnvelopeQueuedEvent,
EnvelopeUnsealedEvent,
ErrorEvent,
FetchLatestEvent,
GroupEvent,
@ -339,8 +340,12 @@ export async function startApp(): Promise<void> {
}
messageReceiver.addEventListener(
'envelope',
queuedEventListener(onEnvelopeReceived, false)
'envelopeUnsealed',
queuedEventListener(onEnvelopeUnsealed, false)
);
messageReceiver.addEventListener(
'envelopeQueued',
queuedEventListener(onEnvelopeQueued, false)
);
messageReceiver.addEventListener(
'message',
@ -2430,9 +2435,15 @@ export async function startApp(): Promise<void> {
{ leading: false }
);
async function onEnvelopeReceived({
async function onEnvelopeQueued({
envelope,
}: EnvelopeEvent): Promise<void> {
}: EnvelopeQueuedEvent): Promise<void> {
throttledSetInboxEnvelopeTimestamp(envelope.serverTimestamp);
}
async function onEnvelopeUnsealed({
envelope,
}: EnvelopeUnsealedEvent): Promise<void> {
throttledSetInboxEnvelopeTimestamp(envelope.serverTimestamp);
const ourUuid = window.textsecure.storage.user.getUuid()?.toString();
@ -2441,7 +2452,7 @@ export async function startApp(): Promise<void> {
window.ConversationController.maybeMergeContacts({
e164: envelope.source,
aci: envelope.sourceUuid,
reason: `onEnvelopeReceived(${envelope.timestamp})`,
reason: `onEnvelopeUnsealed(${envelope.timestamp})`,
});
if (mergePromises.length > 0) {

View file

@ -88,7 +88,8 @@ import type {
} from './Types.d';
import {
EmptyEvent,
EnvelopeEvent,
EnvelopeQueuedEvent,
EnvelopeUnsealedEvent,
ProgressEvent,
TypingEvent,
ErrorEvent,
@ -631,8 +632,13 @@ export default class MessageReceiver
): void;
public override addEventListener(
name: 'envelope',
handler: (ev: EnvelopeEvent) => void
name: 'envelopeQueued',
handler: (ev: EnvelopeQueuedEvent) => void
): void;
public override addEventListener(
name: 'envelopeUnsealed',
handler: (ev: EnvelopeUnsealedEvent) => void
): void;
public override addEventListener(
@ -896,6 +902,19 @@ export default class MessageReceiver
};
// Maintain invariant: encrypted queue => decrypted queue
const envelopeId = getEnvelopeId(decryptedEnvelope);
const taskId = `queueCached(EnvelopeEvent(${envelopeId}))`;
drop(
this.addToQueue(
async () =>
this.dispatchAndWait(
taskId,
new EnvelopeQueuedEvent(decryptedEnvelope)
),
taskId,
TaskType.Decrypted
)
);
drop(
this.addToQueue(
async () => {
@ -1225,11 +1244,14 @@ export default class MessageReceiver
logId = getEnvelopeId(unsealedEnvelope);
const taskId = `dispatchEvent(EnvelopeEvent(${logId}))`;
const taskId = `dispatchEvent(EnvelopeUnsealedEvent(${logId}))`;
drop(
this.addToQueue(
async () =>
this.dispatchAndWait(taskId, new EnvelopeEvent(unsealedEnvelope)),
this.dispatchAndWait(
taskId,
new EnvelopeUnsealedEvent(unsealedEnvelope)
),
taskId,
TaskType.Decrypted
)

View file

@ -104,9 +104,17 @@ export class GroupSyncEvent extends Event {
}
}
export class EnvelopeEvent extends Event {
// Emitted right before we do full decrypt on a message, but after Sealed Sender unseal
export class EnvelopeUnsealedEvent extends Event {
constructor(public readonly envelope: ProcessedEnvelope) {
super('envelope');
super('envelopeUnsealed');
}
}
// Emitted when we queue previously-decrypted events from the cache
export class EnvelopeQueuedEvent extends Event {
constructor(public readonly envelope: ProcessedEnvelope) {
super('envelopeQueued');
}
}