Merge pull request #1012 from yousseefspires/fix/chats-messages

Add unique in Chat by instance/remotejid
This commit is contained in:
Davidson Gomes
2024-11-21 14:48:40 -03:00
committed by GitHub
3 changed files with 18 additions and 6 deletions
+1
View File
@@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0) unreadMessages Int @default(0)
@@index([instanceId]) @@index([instanceId])
@@index([remoteJid]) @@index([remoteJid])
@@unique([instanceId, remoteJid])
} }
model Contact { model Contact {
+1
View File
@@ -127,6 +127,7 @@ model Chat {
unreadMessages Int @default(0) unreadMessages Int @default(0)
@@index([instanceId]) @@index([instanceId])
@@index([remoteJid]) @@index([remoteJid])
@@unique([remoteJid, instanceId])
} }
model Contact { model Contact {
@@ -1147,9 +1147,14 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]); this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) { if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
await this.prismaRepository.chat.create({ try {
data: chatToInsert, await this.prismaRepository.chat.create({
}); data: chatToInsert,
});
}
catch(error){
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
}
} }
} }
@@ -1483,9 +1488,14 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]); this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) { if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
await this.prismaRepository.chat.create({ try {
data: chatToInsert, await this.prismaRepository.chat.create({
}); data: chatToInsert,
});
}
catch(error){
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
}
} }
} }
} }