Skip to content

Commit b55c9fc

Browse files
Merge pull request #2250 from gabrielmouallem/fix/respect-database-save-data-contacts
fix: respect DATABASE_SAVE_DATA_CONTACTS in contact updates
2 parents 86b194a + 08a4795 commit b55c9fc

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export class BaileysStartupService extends ChannelStartupService {
406406
qrcodeTerminal.generate(qr, { small: true }, (qrcode) =>
407407
this.logger.log(
408408
`\n{ instance: ${this.instance.name} pairingCode: ${this.instance.qrcode.pairingCode}, qrcodeCount: ${this.instance.qrcode.count} }\n` +
409-
qrcode,
409+
qrcode,
410410
),
411411
);
412412

@@ -861,10 +861,13 @@ export class BaileysStartupService extends ChannelStartupService {
861861
this.sendDataWebhook(Events.CONTACTS_UPDATE, updatedContacts);
862862
await Promise.all(
863863
updatedContacts.map(async (contact) => {
864-
const update = this.prismaRepository.contact.updateMany({
865-
where: { remoteJid: contact.remoteJid, instanceId: this.instanceId },
866-
data: { profilePicUrl: contact.profilePicUrl },
867-
});
864+
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CONTACTS) {
865+
await this.prismaRepository.contact.updateMany({
866+
where: { remoteJid: contact.remoteJid, instanceId: this.instanceId },
867+
data: { profilePicUrl: contact.profilePicUrl },
868+
});
869+
}
870+
868871

869872
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
870873
const instance = { instanceName: this.instance.name, instanceId: this.instance.id };
@@ -883,8 +886,6 @@ export class BaileysStartupService extends ChannelStartupService {
883886
avatar_url: contact.profilePicUrl,
884887
});
885888
}
886-
887-
return update;
888889
}),
889890
);
890891
}
@@ -908,14 +909,17 @@ export class BaileysStartupService extends ChannelStartupService {
908909

909910
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw);
910911

911-
const updateTransactions = contactsRaw.map((contact) =>
912-
this.prismaRepository.contact.upsert({
913-
where: { remoteJid_instanceId: { remoteJid: contact.remoteJid, instanceId: contact.instanceId } },
914-
create: contact,
915-
update: contact,
916-
}),
917-
);
918-
await this.prismaRepository.$transaction(updateTransactions);
912+
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CONTACTS) {
913+
const updateTransactions = contactsRaw.map((contact) =>
914+
this.prismaRepository.contact.upsert({
915+
where: { remoteJid_instanceId: { remoteJid: contact.remoteJid, instanceId: contact.instanceId } },
916+
create: contact,
917+
update: contact,
918+
}),
919+
);
920+
await this.prismaRepository.$transaction(updateTransactions);
921+
}
922+
919923

920924
//const usersContacts = contactsRaw.filter((c) => c.remoteJid.includes('@s.whatsapp'));
921925
},
@@ -997,16 +1001,16 @@ export class BaileysStartupService extends ChannelStartupService {
9971001

9981002
const messagesRepository: Set<string> = new Set(
9991003
chatwootImport.getRepositoryMessagesCache(instance) ??
1000-
(
1001-
await this.prismaRepository.message.findMany({
1002-
select: { key: true },
1003-
where: { instanceId: this.instanceId },
1004-
})
1005-
).map((message) => {
1006-
const key = message.key as { id: string };
1007-
1008-
return key.id;
1009-
}),
1004+
(
1005+
await this.prismaRepository.message.findMany({
1006+
select: { key: true },
1007+
where: { instanceId: this.instanceId },
1008+
})
1009+
).map((message) => {
1010+
const key = message.key as { id: string };
1011+
1012+
return key.id;
1013+
}),
10101014
);
10111015

10121016
if (chatwootImport.getRepositoryMessagesCache(instance) === null) {

0 commit comments

Comments
 (0)