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

fix: received messages but chat doesnt exists
This commit is contained in:
Davidson Gomes 2024-10-28 17:42:44 -03:00 committed by GitHub
commit e22ff6c0d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View File

@ -382,7 +382,7 @@ export class InstanceController {
return this.waMonitor.instanceInfoById(instanceId, number); return this.waMonitor.instanceInfoById(instanceId, number);
} }
return this.waMonitor.instanceInfo(instanceName); return this.waMonitor.instanceInfo([instanceName]);
} }
public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) { public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) {

View File

@ -1071,6 +1071,25 @@ export class BaileysStartupService extends ChannelStartupService {
if (settings?.groupsIgnore && received.key.remoteJid.includes('@g.us')) { if (settings?.groupsIgnore && received.key.remoteJid.includes('@g.us')) {
continue; continue;
} }
const existingChat = await this.prismaRepository.chat.findFirst({
where: { instanceId: this.instanceId, remoteJid: received.key.remoteJid },
});
if (!!existingChat) {
const chatToInsert = {
remoteJid: received.key.remoteJid,
instanceId: this.instanceId,
name: received.pushName || '',
unreadMessages: 0,
};
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
await this.prismaRepository.chat.create({
data: chatToInsert,
});
}
}
const messageRaw = this.prepareMessage(received); const messageRaw = this.prepareMessage(received);
@ -1386,6 +1405,26 @@ export class BaileysStartupService extends ChannelStartupService {
await this.prismaRepository.messageUpdate.create({ await this.prismaRepository.messageUpdate.create({
data: message, data: message,
}); });
const existingChat = await this.prismaRepository.chat.findFirst({
where: { instanceId: this.instanceId, remoteJid: message.key.remoteJid },
});
if (!!existingChat) {
const chatToInsert = {
remoteJid: message.key.remoteJid,
instanceId: this.instanceId,
name: message.pushName || '',
unreadMessages: 0,
};
this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
await this.prismaRepository.chat.create({
data: chatToInsert,
});
}
}
} }
} }