Skip to content

Commit 27900c2

Browse files
committed
Extracted profile picture request from contacts.upsert function
1 parent 32026d1 commit 27900c2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/whatsapp/services/whatsapp.service.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ export class WAStartupService {
16571657
);
16581658

16591659
this.logger.verbose('Verifying if contacts exists in database to insert');
1660-
const contactsRaw: ContactRaw[] = [];
1660+
let contactsRaw: ContactRaw[] = [];
16611661

16621662
for (const contact of contacts) {
16631663
if (contactsRepository.has(contact.id)) {
@@ -1667,7 +1667,7 @@ export class WAStartupService {
16671667
contactsRaw.push({
16681668
id: contact.id,
16691669
pushName: contact?.name || contact?.verifiedName || contact.id.split('@')[0],
1670-
profilePictureUrl: (await this.profilePicture(contact.id)).profilePictureUrl,
1670+
profilePictureUrl: null,
16711671
owner: this.instance.name,
16721672
});
16731673
}
@@ -1682,6 +1682,23 @@ export class WAStartupService {
16821682
this.chatwootService.addHistoryContacts({ instanceName: this.instance.name }, contactsRaw);
16831683
chatwootImport.importHistoryContacts({ instanceName: this.instance.name }, this.localChatwoot);
16841684
}
1685+
1686+
// Update profile pictures
1687+
contactsRaw = [];
1688+
for await (const contact of contacts) {
1689+
contactsRaw.push({
1690+
id: contact.id,
1691+
pushName: contact?.name || contact?.verifiedName || contact.id.split('@')[0],
1692+
profilePictureUrl: (await this.profilePicture(contact.id)).profilePictureUrl,
1693+
owner: this.instance.name,
1694+
});
1695+
}
1696+
1697+
this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE');
1698+
this.sendDataWebhook(Events.CONTACTS_UPSERT, contactsRaw);
1699+
1700+
this.logger.verbose('Updating contacts in database');
1701+
this.repository.contact.update(contactsRaw, this.instance.name, database.SAVE_DATA.CONTACTS);
16851702
} catch (error) {
16861703
this.logger.error(error);
16871704
}

0 commit comments

Comments
 (0)