Merge pull request #2250 from gabrielmouallem/fix/respect-database-save-data-contacts

fix: respect DATABASE_SAVE_DATA_CONTACTS in contact updates
This commit is contained in:
Davidson Gomes 2025-12-05 11:01:46 -03:00 committed by GitHub
commit b55c9fcab7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -861,10 +861,13 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CONTACTS_UPDATE, updatedContacts); this.sendDataWebhook(Events.CONTACTS_UPDATE, updatedContacts);
await Promise.all( await Promise.all(
updatedContacts.map(async (contact) => { updatedContacts.map(async (contact) => {
const update = this.prismaRepository.contact.updateMany({ if (this.configService.get<Database>('DATABASE').SAVE_DATA.CONTACTS) {
await this.prismaRepository.contact.updateMany({
where: { remoteJid: contact.remoteJid, instanceId: this.instanceId }, where: { remoteJid: contact.remoteJid, instanceId: this.instanceId },
data: { profilePicUrl: contact.profilePicUrl }, data: { profilePicUrl: contact.profilePicUrl },
}); });
}
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
const instance = { instanceName: this.instance.name, instanceId: this.instance.id }; const instance = { instanceName: this.instance.name, instanceId: this.instance.id };
@ -883,8 +886,6 @@ export class BaileysStartupService extends ChannelStartupService {
avatar_url: contact.profilePicUrl, avatar_url: contact.profilePicUrl,
}); });
} }
return update;
}), }),
); );
} }
@ -908,6 +909,7 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw); this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CONTACTS) {
const updateTransactions = contactsRaw.map((contact) => const updateTransactions = contactsRaw.map((contact) =>
this.prismaRepository.contact.upsert({ this.prismaRepository.contact.upsert({
where: { remoteJid_instanceId: { remoteJid: contact.remoteJid, instanceId: contact.instanceId } }, where: { remoteJid_instanceId: { remoteJid: contact.remoteJid, instanceId: contact.instanceId } },
@ -916,6 +918,8 @@ export class BaileysStartupService extends ChannelStartupService {
}), }),
); );
await this.prismaRepository.$transaction(updateTransactions); await this.prismaRepository.$transaction(updateTransactions);
}
//const usersContacts = contactsRaw.filter((c) => c.remoteJid.includes('@s.whatsapp')); //const usersContacts = contactsRaw.filter((c) => c.remoteJid.includes('@s.whatsapp'));
}, },