@@ -152,13 +152,7 @@ import { v4 } from 'uuid';
152152import { BaileysMessageProcessor } from './baileysMessage.processor' ;
153153import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys' ;
154154
155- export interface ExtendedMessageKey extends WAMessageKey {
156- senderPn ?: string ;
157- previousRemoteJid ?: string | null ;
158- }
159-
160155export interface ExtendedIMessageKey extends proto . IMessageKey {
161- senderPn ?: string ;
162156 remoteJidAlt ?: string ;
163157 participantAlt ?: string ;
164158 server_id ?: string ;
@@ -1004,10 +998,6 @@ export class BaileysStartupService extends ChannelStartupService {
1004998 continue ;
1005999 }
10061000
1007- if ( m . key . remoteJid ?. includes ( '@lid' ) && ( m . key as ExtendedIMessageKey ) . senderPn ) {
1008- m . key . remoteJid = ( m . key as ExtendedIMessageKey ) . senderPn ;
1009- }
1010-
10111001 if ( Long . isLong ( m ?. messageTimestamp ) ) {
10121002 m . messageTimestamp = m . messageTimestamp ?. toNumber ( ) ;
10131003 }
@@ -1069,16 +1059,7 @@ export class BaileysStartupService extends ChannelStartupService {
10691059 settings : any ,
10701060 ) => {
10711061 try {
1072- // Garantir que localChatwoot está carregado antes de processar mensagens
1073- if ( this . configService . get < Chatwoot > ( 'CHATWOOT' ) . ENABLED && ! this . localChatwoot ?. enabled ) {
1074- await this . loadChatwoot ( ) ;
1075- }
1076-
10771062 for ( const received of messages ) {
1078- if ( received . key . remoteJid ?. includes ( '@lid' ) && ( received . key as ExtendedMessageKey ) . senderPn ) {
1079- ( received . key as ExtendedMessageKey ) . previousRemoteJid = received . key . remoteJid ;
1080- received . key . remoteJid = ( received . key as ExtendedMessageKey ) . senderPn ;
1081- }
10821063 if (
10831064 received ?. messageStubParameters ?. some ?.( ( param ) =>
10841065 [
@@ -1126,9 +1107,9 @@ export class BaileysStartupService extends ChannelStartupService {
11261107 await this . sendDataWebhook ( Events . MESSAGES_EDITED , editedMessage ) ;
11271108 const oldMessage = await this . getMessage ( editedMessage . key , true ) ;
11281109 if ( ( oldMessage as any ) ?. id ) {
1129- const editedMessageTimestamp = Long . isLong ( editedMessage ?. timestampMs )
1130- ? Math . floor ( editedMessage . timestampMs . toNumber ( ) / 1000 )
1131- : Math . floor ( ( editedMessage . timestampMs as number ) / 1000 ) ;
1110+ const editedMessageTimestamp = Long . isLong ( received ?. messageTimestamp )
1111+ ? Math . floor ( received ?. messageTimestamp . toNumber ( ) )
1112+ : Math . floor ( received ?. messageTimestamp as number ) ;
11321113
11331114 await this . prismaRepository . message . update ( {
11341115 where : { id : ( oldMessage as any ) . id } ,
@@ -1367,10 +1348,6 @@ export class BaileysStartupService extends ChannelStartupService {
13671348 }
13681349 }
13691350
1370- if ( messageRaw . key . remoteJid ?. includes ( '@lid' ) && messageRaw . key . remoteJidAlt ) {
1371- messageRaw . key . remoteJid = messageRaw . key . remoteJidAlt ;
1372- }
1373-
13741351 this . logger . log ( messageRaw ) ;
13751352
13761353 this . sendDataWebhook ( Events . MESSAGES_UPSERT , messageRaw ) ;
@@ -1446,25 +1423,18 @@ export class BaileysStartupService extends ChannelStartupService {
14461423 continue ;
14471424 }
14481425
1449- if ( key . remoteJid ?. includes ( '@lid' ) && key . remoteJidAlt ) {
1450- key . remoteJid = key . remoteJidAlt ;
1451- }
1426+ if ( update . message !== null && update . status === undefined ) continue ;
14521427
14531428 const updateKey = `${ this . instance . id } _${ key . id } _${ update . status } ` ;
14541429
14551430 const cached = await this . baileysCache . get ( updateKey ) ;
14561431
1457- // Não ignorar mensagens deletadas (messageStubType === 1) mesmo que estejam em cache
1458- const isDeletedMessage = update . messageStubType === 1 ;
1459-
1460- if ( cached && ! isDeletedMessage ) {
1432+ if ( cached ) {
14611433 this . logger . info ( `Message duplicated ignored [avoid deadlock]: ${ updateKey } ` ) ;
14621434 continue ;
14631435 }
14641436
1465- if ( ! isDeletedMessage ) {
1466- await this . baileysCache . set ( updateKey , true , this . UPDATE_CACHE_TTL_SECONDS ) ;
1467- }
1437+ await this . baileysCache . set ( updateKey , true , 30 * 60 ) ;
14681438
14691439 if ( status [ update . status ] === 'READ' && key . fromMe ) {
14701440 if ( this . configService . get < Chatwoot > ( 'CHATWOOT' ) . ENABLED && this . localChatwoot ?. enabled ) {
@@ -1494,7 +1464,7 @@ export class BaileysStartupService extends ChannelStartupService {
14941464 keyId : key . id ,
14951465 remoteJid : key ?. remoteJid ,
14961466 fromMe : key . fromMe ,
1497- participant : key ?. remoteJid ,
1467+ participant : key ?. participant ,
14981468 status : status [ update . status ] ?? 'DELETED' ,
14991469 pollUpdates,
15001470 instanceId : this . instanceId ,
@@ -1568,22 +1538,8 @@ export class BaileysStartupService extends ChannelStartupService {
15681538
15691539 this . sendDataWebhook ( Events . MESSAGES_UPDATE , message ) ;
15701540
1571- if ( this . configService . get < Database > ( 'DATABASE' ) . SAVE_DATA . MESSAGE_UPDATE ) {
1572- // Verificar se a mensagem ainda existe antes de criar o update
1573- const messageExists = await this . prismaRepository . message . findFirst ( {
1574- where : {
1575- instanceId : message . instanceId ,
1576- key : {
1577- path : [ 'id' ] ,
1578- equals : message . keyId ,
1579- } ,
1580- } ,
1581- } ) ;
1582-
1583- if ( messageExists ) {
1584- await this . prismaRepository . messageUpdate . create ( { data : message } ) ;
1585- }
1586- }
1541+ if ( this . configService . get < Database > ( 'DATABASE' ) . SAVE_DATA . MESSAGE_UPDATE )
1542+ await this . prismaRepository . messageUpdate . create ( { data : message } ) ;
15871543
15881544 const existingChat = await this . prismaRepository . chat . findFirst ( {
15891545 where : { instanceId : this . instanceId , remoteJid : message . remoteJid } ,
@@ -3453,18 +3409,13 @@ export class BaileysStartupService extends ChannelStartupService {
34533409 }
34543410
34553411 const numberJid = numberVerified ?. jid || user . jid ;
3456- // const lid =
3457- // typeof numberVerified?.lid === 'string'
3458- // ? numberVerified.lid
3459- // : numberJid.includes('@lid')
3460- // ? numberJid.split('@')[1]
3461- // : undefined;
3412+
34623413 return new OnWhatsAppDto (
34633414 numberJid ,
34643415 ! ! numberVerified ?. exists ,
34653416 user . number ,
34663417 contacts . find ( ( c ) => c . remoteJid === numberJid ) ?. pushName ,
3467- // lid ,
3418+ undefined ,
34683419 ) ;
34693420 } ) ,
34703421 ) ;
@@ -3616,7 +3567,7 @@ export class BaileysStartupService extends ChannelStartupService {
36163567 keyId : messageId ,
36173568 remoteJid : response . key . remoteJid ,
36183569 fromMe : response . key . fromMe ,
3619- participant : response . key ?. remoteJid ,
3570+ participant : response . key ?. participant ,
36203571 status : 'DELETED' ,
36213572 instanceId : this . instanceId ,
36223573 } ;
@@ -3676,7 +3627,10 @@ export class BaileysStartupService extends ChannelStartupService {
36763627 }
36773628 }
36783629
3679- if ( 'messageContextInfo' in msg . message && Object . keys ( msg . message ) . length === 1 ) {
3630+ if (
3631+ Object . keys ( msg . message ) . length === 1 &&
3632+ Object . prototype . hasOwnProperty . call ( msg . message , 'messageContextInfo' )
3633+ ) {
36803634 throw 'The message is messageContextInfo' ;
36813635 }
36823636
@@ -4051,7 +4005,7 @@ export class BaileysStartupService extends ChannelStartupService {
40514005 keyId : messageId ,
40524006 remoteJid : messageSent . key . remoteJid ,
40534007 fromMe : messageSent . key . fromMe ,
4054- participant : messageSent . key ?. remoteJid ,
4008+ participant : messageSent . key ?. participant ,
40554009 status : 'EDITED' ,
40564010 instanceId : this . instanceId ,
40574011 } ;
@@ -4647,9 +4601,7 @@ export class BaileysStartupService extends ChannelStartupService {
46474601 return response ;
46484602 }
46494603
4650- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4651- public async baileysAssertSessions ( jids : string [ ] , _force ?: boolean ) {
4652- // Note: _force parameter kept for API compatibility but not used in Baileys 7.0.0-rc.5+
4604+ public async baileysAssertSessions ( jids : string [ ] ) {
46534605 const response = await this . client . assertSessions ( jids ) ;
46544606
46554607 return response ;
@@ -4854,7 +4806,7 @@ export class BaileysStartupService extends ChannelStartupService {
48544806 {
48554807 OR : [
48564808 keyFilters ?. remoteJid ? { key : { path : [ 'remoteJid' ] , equals : keyFilters ?. remoteJid } } : { } ,
4857- keyFilters ?. senderPn ? { key : { path : [ 'senderPn ' ] , equals : keyFilters ?. senderPn } } : { } ,
4809+ keyFilters ?. remoteJidAlt ? { key : { path : [ 'remoteJidAlt ' ] , equals : keyFilters ?. remoteJidAlt } } : { } ,
48584810 ] ,
48594811 } ,
48604812 ] ,
@@ -4884,7 +4836,7 @@ export class BaileysStartupService extends ChannelStartupService {
48844836 {
48854837 OR : [
48864838 keyFilters ?. remoteJid ? { key : { path : [ 'remoteJid' ] , equals : keyFilters ?. remoteJid } } : { } ,
4887- keyFilters ?. senderPn ? { key : { path : [ 'senderPn ' ] , equals : keyFilters ?. senderPn } } : { } ,
4839+ keyFilters ?. remoteJidAlt ? { key : { path : [ 'remoteJidAlt ' ] , equals : keyFilters ?. remoteJidAlt } } : { } ,
48884840 ] ,
48894841 } ,
48904842 ] ,
0 commit comments