@@ -1071,6 +1071,25 @@ export class BaileysStartupService extends ChannelStartupService {
10711071 if (settings?.groupsIgnore && received.key.remoteJid.includes('@g.us')) {
10721072 continue;
10731073 }
1074+ const existingChat = await this.prismaRepository.chat.findFirst({
1075+ where: { instanceId: this.instanceId, remoteJid: received.key.remoteJid },
1076+ });
1077+
1078+ if (!!existingChat) {
1079+ const chatToInsert = {
1080+ remoteJid: received.key.remoteJid,
1081+ instanceId: this.instanceId,
1082+ name: received.pushName || '',
1083+ unreadMessages: 0,
1084+ };
1085+
1086+ this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
1087+ if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
1088+ await this.prismaRepository.chat.create({
1089+ data: chatToInsert,
1090+ });
1091+ }
1092+ }
10741093
10751094 const messageRaw = this.prepareMessage(received);
10761095
@@ -1386,6 +1405,26 @@ export class BaileysStartupService extends ChannelStartupService {
13861405 await this.prismaRepository.messageUpdate.create({
13871406 data: message,
13881407 });
1408+
1409+ const existingChat = await this.prismaRepository.chat.findFirst({
1410+ where: { instanceId: this.instanceId, remoteJid: message.key.remoteJid },
1411+ });
1412+
1413+ if (!!existingChat) {
1414+ const chatToInsert = {
1415+ remoteJid: message.key.remoteJid,
1416+ instanceId: this.instanceId,
1417+ name: message.pushName || '',
1418+ unreadMessages: 0,
1419+ };
1420+
1421+ this.sendDataWebhook(Events.CHATS_UPSERT, [chatToInsert]);
1422+ if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
1423+ await this.prismaRepository.chat.create({
1424+ data: chatToInsert,
1425+ });
1426+ }
1427+ }
13891428 }
13901429 }
13911430
0 commit comments