MessageReceiver: Emit envelope event on queue for cached+decrypted items
This commit is contained in:
parent
3bf8adf6e1
commit
8177a4e2b3
3 changed files with 54 additions and 13 deletions
|
@ -83,7 +83,8 @@ import type {
|
||||||
ConfigurationEvent,
|
ConfigurationEvent,
|
||||||
DecryptionErrorEvent,
|
DecryptionErrorEvent,
|
||||||
DeliveryEvent,
|
DeliveryEvent,
|
||||||
EnvelopeEvent,
|
EnvelopeQueuedEvent,
|
||||||
|
EnvelopeUnsealedEvent,
|
||||||
ErrorEvent,
|
ErrorEvent,
|
||||||
FetchLatestEvent,
|
FetchLatestEvent,
|
||||||
GroupEvent,
|
GroupEvent,
|
||||||
|
@ -339,8 +340,12 @@ export async function startApp(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
messageReceiver.addEventListener(
|
messageReceiver.addEventListener(
|
||||||
'envelope',
|
'envelopeUnsealed',
|
||||||
queuedEventListener(onEnvelopeReceived, false)
|
queuedEventListener(onEnvelopeUnsealed, false)
|
||||||
|
);
|
||||||
|
messageReceiver.addEventListener(
|
||||||
|
'envelopeQueued',
|
||||||
|
queuedEventListener(onEnvelopeQueued, false)
|
||||||
);
|
);
|
||||||
messageReceiver.addEventListener(
|
messageReceiver.addEventListener(
|
||||||
'message',
|
'message',
|
||||||
|
@ -2430,9 +2435,15 @@ export async function startApp(): Promise<void> {
|
||||||
{ leading: false }
|
{ leading: false }
|
||||||
);
|
);
|
||||||
|
|
||||||
async function onEnvelopeReceived({
|
async function onEnvelopeQueued({
|
||||||
envelope,
|
envelope,
|
||||||
}: EnvelopeEvent): Promise<void> {
|
}: EnvelopeQueuedEvent): Promise<void> {
|
||||||
|
throttledSetInboxEnvelopeTimestamp(envelope.serverTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onEnvelopeUnsealed({
|
||||||
|
envelope,
|
||||||
|
}: EnvelopeUnsealedEvent): Promise<void> {
|
||||||
throttledSetInboxEnvelopeTimestamp(envelope.serverTimestamp);
|
throttledSetInboxEnvelopeTimestamp(envelope.serverTimestamp);
|
||||||
|
|
||||||
const ourUuid = window.textsecure.storage.user.getUuid()?.toString();
|
const ourUuid = window.textsecure.storage.user.getUuid()?.toString();
|
||||||
|
@ -2441,7 +2452,7 @@ export async function startApp(): Promise<void> {
|
||||||
window.ConversationController.maybeMergeContacts({
|
window.ConversationController.maybeMergeContacts({
|
||||||
e164: envelope.source,
|
e164: envelope.source,
|
||||||
aci: envelope.sourceUuid,
|
aci: envelope.sourceUuid,
|
||||||
reason: `onEnvelopeReceived(${envelope.timestamp})`,
|
reason: `onEnvelopeUnsealed(${envelope.timestamp})`,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (mergePromises.length > 0) {
|
if (mergePromises.length > 0) {
|
||||||
|
|
|
@ -88,7 +88,8 @@ import type {
|
||||||
} from './Types.d';
|
} from './Types.d';
|
||||||
import {
|
import {
|
||||||
EmptyEvent,
|
EmptyEvent,
|
||||||
EnvelopeEvent,
|
EnvelopeQueuedEvent,
|
||||||
|
EnvelopeUnsealedEvent,
|
||||||
ProgressEvent,
|
ProgressEvent,
|
||||||
TypingEvent,
|
TypingEvent,
|
||||||
ErrorEvent,
|
ErrorEvent,
|
||||||
|
@ -631,8 +632,13 @@ export default class MessageReceiver
|
||||||
): void;
|
): void;
|
||||||
|
|
||||||
public override addEventListener(
|
public override addEventListener(
|
||||||
name: 'envelope',
|
name: 'envelopeQueued',
|
||||||
handler: (ev: EnvelopeEvent) => void
|
handler: (ev: EnvelopeQueuedEvent) => void
|
||||||
|
): void;
|
||||||
|
|
||||||
|
public override addEventListener(
|
||||||
|
name: 'envelopeUnsealed',
|
||||||
|
handler: (ev: EnvelopeUnsealedEvent) => void
|
||||||
): void;
|
): void;
|
||||||
|
|
||||||
public override addEventListener(
|
public override addEventListener(
|
||||||
|
@ -896,6 +902,19 @@ export default class MessageReceiver
|
||||||
};
|
};
|
||||||
|
|
||||||
// Maintain invariant: encrypted queue => decrypted queue
|
// 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(
|
drop(
|
||||||
this.addToQueue(
|
this.addToQueue(
|
||||||
async () => {
|
async () => {
|
||||||
|
@ -1225,11 +1244,14 @@ export default class MessageReceiver
|
||||||
|
|
||||||
logId = getEnvelopeId(unsealedEnvelope);
|
logId = getEnvelopeId(unsealedEnvelope);
|
||||||
|
|
||||||
const taskId = `dispatchEvent(EnvelopeEvent(${logId}))`;
|
const taskId = `dispatchEvent(EnvelopeUnsealedEvent(${logId}))`;
|
||||||
drop(
|
drop(
|
||||||
this.addToQueue(
|
this.addToQueue(
|
||||||
async () =>
|
async () =>
|
||||||
this.dispatchAndWait(taskId, new EnvelopeEvent(unsealedEnvelope)),
|
this.dispatchAndWait(
|
||||||
|
taskId,
|
||||||
|
new EnvelopeUnsealedEvent(unsealedEnvelope)
|
||||||
|
),
|
||||||
taskId,
|
taskId,
|
||||||
TaskType.Decrypted
|
TaskType.Decrypted
|
||||||
)
|
)
|
||||||
|
|
|
@ -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) {
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue