@@ -63,6 +63,8 @@ import makeWASocket, {
6363 proto ,
6464 useMultiFileAuthState ,
6565 UserFacingSocketConfig ,
66+ USyncQuery ,
67+ USyncUser ,
6668 WABrowserDescription ,
6769 WACallEvent ,
6870 WAConnectionState ,
@@ -443,8 +445,8 @@ export class WAStartupService {
443445 return ;
444446 }
445447
446- this . instanceQr . base64 = base64 ;
447448 this . instanceQr . code = qr ;
449+ this . instanceQr . base64 = base64 ;
448450
449451 this . ws . send ( this . instance . name , 'qrcode.updated' , this . instanceQr ) ;
450452
@@ -561,7 +563,6 @@ export class WAStartupService {
561563 this . authState = await this . defineAuthState ( ) ;
562564
563565 const { version } = fetchLatestBaileysVersionV2 ( ) ;
564- console . log ( { version } ) ;
565566 const session = this . configService . get < ConfigSessionPhone > ( 'CONFIG_SESSION_PHONE' ) ;
566567 const browser : WABrowserDescription = ! this . phoneNumber
567568 ? [ session . CLIENT , session . NAME , release ( ) ]
@@ -2008,28 +2009,59 @@ export class WAStartupService {
20082009 for await ( const number of data . numbers ) {
20092010 const jid = this . createJid ( number ) ;
20102011 if ( isLidUser ( jid ) ) {
2011- onWhatsapp . push ( new OnWhatsAppDto ( jid , true , jid ) ) ;
2012+ onWhatsapp . push ( new OnWhatsAppDto ( true , '' , jid ) ) ;
20122013 }
20132014 if ( isJidGroup ( jid ) ) {
20142015 const group = await this . findGroup ( { groupJid : jid } , 'inner' ) ;
2015- onWhatsapp . push ( new OnWhatsAppDto ( group . id , ! ! group ? .id , '' , group ?. subject ) ) ;
2016+ onWhatsapp . push ( new OnWhatsAppDto ( ! ! group ? .id , group . id , '' , group ?. subject ) ) ;
20162017 } else if ( jid . includes ( '@broadcast' ) ) {
2017- onWhatsapp . push ( new OnWhatsAppDto ( jid , true ) ) ;
2018+ onWhatsapp . push ( new OnWhatsAppDto ( true , jid ) ) ;
20182019 } else {
20192020 try {
20202021 const result = ( await this . client . onWhatsApp ( jid ) ) [ 0 ] ;
2022+
2023+ let lid : string | undefined ;
2024+ if ( result ?. exists ) {
2025+ const item = ( await this . getLid ( result . jid ) ) [ 0 ]
2026+ lid = item ?. lid
2027+ }
20212028 onWhatsapp . push (
2022- new OnWhatsAppDto ( result . jid , ! ! result . exists , result ?. [ 'lid' ] as string ) ,
2029+ new OnWhatsAppDto ( ! ! result . exists , result . jid , lid ) ,
20232030 ) ;
20242031 } catch ( error ) {
2025- onWhatsapp . push ( new OnWhatsAppDto ( number , false ) ) ;
2032+ onWhatsapp . push ( new OnWhatsAppDto ( false , number ) ) ;
20262033 }
20272034 }
20282035 }
20292036
20302037 return onWhatsapp ;
20312038 }
20322039
2040+ public async getLid ( ...jids : string [ ] ) : Promise < { id : string , lid : string } [ ] > {
2041+ const q = new USyncQuery ( ) . withLIDProtocol ( ) . withContext ( 'background' ) ;
2042+
2043+ for ( const jid of jids ) {
2044+ if ( isLidUser ( jid ) ) {
2045+ continue ;
2046+ }
2047+
2048+ q . withUser ( new USyncUser ( ) . withId ( jid ) ) ;
2049+ }
2050+
2051+ if ( q . users . length === 0 ) {
2052+ return [ ] ;
2053+ }
2054+
2055+ const results = await this . client . executeUSyncQuery ( q ) ;
2056+ if ( results ) {
2057+ return results . list .
2058+ filter ( i => ! ! i ?. lid )
2059+ . map ( ( { lid, id } ) => ( { lid, id } ) as { id : string , lid : string } ) ;
2060+ }
2061+
2062+ return [ ] ;
2063+ }
2064+
20332065 /**
20342066 * @deprecated
20352067 */
0 commit comments