Refactor contact sync processing

This commit is contained in:
Fedor Indutny 2022-08-24 22:04:42 -07:00 committed by GitHub
parent 76e73f63dc
commit 7ce4beb270
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 229 additions and 156 deletions

View file

@ -104,7 +104,6 @@ import {
StickerPackEvent,
ReadSyncEvent,
ViewSyncEvent,
ContactEvent,
ContactSyncEvent,
GroupEvent,
GroupSyncEvent,
@ -561,11 +560,6 @@ export default class MessageReceiver
handler: (ev: ViewSyncEvent) => void
): void;
public override addEventListener(
name: 'contact',
handler: (ev: ContactEvent) => void
): void;
public override addEventListener(
name: 'contactSync',
handler: (ev: ContactSyncEvent) => void
@ -2748,6 +2742,9 @@ export default class MessageReceiver
return this.handleSentMessage(envelope, sentMessage);
}
if (syncMessage.contacts) {
// Note: we do not return here because we don't want to block the next
// message on this attachment download and a lot of processing of that
// attachment.
this.handleContacts(envelope, syncMessage.contacts);
return;
}
@ -3068,26 +3065,14 @@ export default class MessageReceiver
this.removeFromCache(envelope);
// Note: we do not return here because we don't want to block the next message on
// this attachment download and a lot of processing of that attachment.
const attachmentPointer = await this.handleAttachment(blob);
const results = [];
const contactBuffer = new ContactBuffer(attachmentPointer.data);
let contactDetails = contactBuffer.next();
while (contactDetails !== undefined) {
const contactEvent = new ContactEvent(
contactDetails,
envelope.receivedAtCounter
);
results.push(this.dispatchAndWait(contactEvent));
contactDetails = contactBuffer.next();
}
await Promise.all(results);
const finalEvent = new ContactSyncEvent();
await this.dispatchAndWait(finalEvent);
const contactSync = new ContactSyncEvent(
Array.from(contactBuffer),
envelope.receivedAtCounter
);
await this.dispatchAndWait(contactSync);
log.info('handleContacts: finished');
}