@@ -58,7 +58,7 @@ import { PrismaRepository } from '@api/repository/repository.service';
5858import { chatbotController , waMonitor } from '@api/server.module' ;
5959import { CacheService } from '@api/services/cache.service' ;
6060import { ChannelStartupService } from '@api/services/channel.service' ;
61- import { Events , MessageSubtype , TypeMediaMessage , wa } from '@api/types/wa.types' ;
61+ import { Events , LidContact , LidMessageKey , MessageSubtype , resolveLidContact , resolveLidJid , TypeMediaMessage , wa } from '@api/types/wa.types' ;
6262import { CacheEngine } from '@cache/cacheengine' ;
6363import {
6464 CacheConf ,
@@ -779,12 +779,10 @@ export class BaileysStartupService extends ChannelStartupService {
779779 } ;
780780
781781 private readonly contactHandle = {
782- 'contacts.upsert' : async ( contacts : Contact [ ] ) => {
782+ 'contacts.upsert' : async ( contacts : LidContact [ ] ) => {
783783 try {
784784 const contactsRaw : any = contacts . map ( ( contact ) => ( {
785- remoteJid : contact . id . includes ( '@lid' ) && ( contact as any ) ?. lidJidAlt
786- ? ( contact as any ) . lidJidAlt
787- : contact . id ,
785+ remoteJid : resolveLidContact ( contact ) ,
788786 pushName : contact ?. name || contact ?. verifiedName || contact . id . split ( '@' ) [ 0 ] ,
789787 profilePicUrl : null ,
790788 instanceId : this . instanceId ,
@@ -822,10 +820,8 @@ export class BaileysStartupService extends ChannelStartupService {
822820 }
823821
824822 const updatedContacts = await Promise . all (
825- contacts . map ( async ( contact ) => ( {
826- remoteJid : contact . id . includes ( '@lid' ) && ( contact as any ) ?. lidJidAlt
827- ? ( contact as any ) . lidJidAlt
828- : contact . id ,
823+ contacts . map ( async ( contact : LidContact ) => ( {
824+ remoteJid : resolveLidContact ( contact ) ,
829825 pushName : contact ?. name || contact ?. verifiedName || contact . id . split ( '@' ) [ 0 ] ,
830826 profilePicUrl : ( await this . profilePicture ( contact . id ) ) . profilePictureUrl ,
831827 instanceId : this . instanceId ,
@@ -1143,8 +1139,8 @@ export class BaileysStartupService extends ChannelStartupService {
11431139 }
11441140
11451141 // Resolve @lid to @s.whatsapp.net so all downstream uses (prepareMessage, chatbot, contact) get the correct JID
1146- if ( received . key . remoteJid ?. includes ( '@lid' ) && ( received . key as any ) ?. remoteJidAlt ) {
1147- received . key . remoteJid = ( received . key as any ) . remoteJidAlt ;
1142+ if ( received . key . remoteJid ?. includes ( '@lid' ) && ( received . key as LidMessageKey ) ?. remoteJidAlt ) {
1143+ received . key . remoteJid = ( received . key as LidMessageKey ) . remoteJidAlt ;
11481144 }
11491145
11501146 if ( settings ?. groupsIgnore && received . key . remoteJid . includes ( '@g.us' ) ) {
@@ -1426,8 +1422,9 @@ export class BaileysStartupService extends ChannelStartupService {
14261422 }
14271423
14281424 // Resolve @lid to @s.whatsapp.net using the stored message key as source of truth
1425+ const lidKey = key as LidMessageKey ;
14291426 const resolvedRemoteJid : string = key . remoteJid ?. includes ( '@lid' )
1430- ? ( ( key as any ) ? .remoteJidAlt ?? ( findMessage . key as any ) ?. remoteJid ?? key . remoteJid )
1427+ ? ( lidKey . remoteJidAlt ?? ( findMessage . key as LidMessageKey ) ?. remoteJid ?? key . remoteJid )
14311428 : key . remoteJid ;
14321429
14331430 if ( update . message === null && update . status === undefined ) {
@@ -1676,9 +1673,7 @@ export class BaileysStartupService extends ChannelStartupService {
16761673 for ( const event of payload ) {
16771674 if ( typeof event . key . remoteJid === 'string' && typeof event . receipt . readTimestamp === 'number' ) {
16781675 // Resolve @lid to @s.whatsapp.net so read receipts match stored messages
1679- const jid = event . key . remoteJid . includes ( '@lid' ) && ( event . key as any ) ?. remoteJidAlt
1680- ? ( event . key as any ) . remoteJidAlt
1681- : event . key . remoteJid ;
1676+ const jid = resolveLidJid ( event . key as LidMessageKey ) ;
16821677 remotesJidMap [ jid ] = event . receipt . readTimestamp ;
16831678 }
16841679 }
0 commit comments