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