@@ -145,7 +145,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
145145 logger . debug ( { messageKey } , 'already requested resend' )
146146 return
147147 } else {
148- placeholderResendCache . set ( messageKey ?. id ! , true )
148+ await placeholderResendCache . set ( messageKey ?. id ! , true )
149149 }
150150
151151 await delay ( 5000 )
@@ -164,10 +164,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
164164 peerDataOperationRequestType : proto . Message . PeerDataOperationRequestType . PLACEHOLDER_MESSAGE_RESEND
165165 }
166166
167- setTimeout ( ( ) => {
167+ setTimeout ( async ( ) => {
168168 if ( placeholderResendCache . get ( messageKey ?. id ! ) ) {
169169 logger . debug ( { messageKey } , 'PDO message without response after 15 seconds. Phone possibly offline' )
170- placeholderResendCache . del ( messageKey ?. id ! )
170+ await placeholderResendCache . del ( messageKey ?. id ! )
171171 }
172172 } , 15_000 )
173173
@@ -403,14 +403,14 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
403403
404404 // Use the new retry count for the rest of the logic
405405 const key = `${ msgId } :${ msgKey ?. participant } `
406- msgRetryCache . set ( key , retryCount )
406+ await msgRetryCache . set ( key , retryCount )
407407 } else {
408408 // Fallback to old system
409409 const key = `${ msgId } :${ msgKey ?. participant } `
410410 let retryCount = ( await msgRetryCache . get < number > ( key ) ) || 0
411411 if ( retryCount >= maxMsgRetryCount ) {
412412 logger . debug ( { retryCount, msgId } , 'reached retry limit, clearing' )
413- msgRetryCache . del ( key )
413+ await msgRetryCache . del ( key )
414414 return
415415 }
416416
@@ -1031,7 +1031,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
10311031 if ( ! ids [ i ] ) continue
10321032
10331033 if ( msg && ( await willSendMessageAgain ( ids [ i ] , participant ) ) ) {
1034- updateSendMessageAgainCount ( ids [ i ] , participant )
1034+ await updateSendMessageAgainCount ( ids [ i ] , participant )
10351035 const msgRelayOpts : MessageRelayOptions = { messageId : ids [ i ] }
10361036
10371037 if ( sendToAll ) {
@@ -1122,7 +1122,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
11221122 if ( ids [ 0 ] && key . participant && ( await willSendMessageAgain ( ids [ 0 ] , key . participant ) ) ) {
11231123 if ( key . fromMe ) {
11241124 try {
1125- updateSendMessageAgainCount ( ids [ 0 ] , key . participant )
1125+ await updateSendMessageAgainCount ( ids [ 0 ] , key . participant )
11261126 logger . debug ( { attrs, key } , 'recv retry request' )
11271127 await sendMessagesAgain ( key , ids , retryNode ! )
11281128 } catch ( error : unknown ) {
@@ -1257,7 +1257,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
12571257 logger . debug ( `[handleMessage] Attempting retry request for failed decryption` )
12581258
12591259 // Handle both pre-key and normal retries in single mutex
1260- retryMutex . mutex ( async ( ) => {
1260+ await retryMutex . mutex ( async ( ) => {
12611261 try {
12621262 if ( ! ws . isOpen ) {
12631263 logger . debug ( { node } , 'Connection closed, skipping retry' )
@@ -1499,7 +1499,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
14991499
15001500 const offlineNodeProcessor = makeOfflineNodeProcessor ( )
15011501
1502- const processNode = (
1502+ const processNode = async (
15031503 type : MessageType ,
15041504 node : BinaryNode ,
15051505 identifier : string ,
@@ -1510,31 +1510,31 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
15101510 if ( isOffline ) {
15111511 offlineNodeProcessor . enqueue ( type , node )
15121512 } else {
1513- processNodeWithBuffer ( node , identifier , exec )
1513+ await processNodeWithBuffer ( node , identifier , exec )
15141514 }
15151515 }
15161516
15171517 // recv a message
1518- ws . on ( 'CB:message' , ( node : BinaryNode ) => {
1519- processNode ( 'message' , node , 'processing message' , handleMessage )
1518+ ws . on ( 'CB:message' , async ( node : BinaryNode ) => {
1519+ await processNode ( 'message' , node , 'processing message' , handleMessage )
15201520 } )
15211521
15221522 ws . on ( 'CB:call' , async ( node : BinaryNode ) => {
1523- processNode ( 'call' , node , 'handling call' , handleCall )
1523+ await processNode ( 'call' , node , 'handling call' , handleCall )
15241524 } )
15251525
1526- ws . on ( 'CB:receipt' , node => {
1527- processNode ( 'receipt' , node , 'handling receipt' , handleReceipt )
1526+ ws . on ( 'CB:receipt' , async node => {
1527+ await processNode ( 'receipt' , node , 'handling receipt' , handleReceipt )
15281528 } )
15291529
15301530 ws . on ( 'CB:notification' , async ( node : BinaryNode ) => {
1531- processNode ( 'notification' , node , 'handling notification' , handleNotification )
1531+ await processNode ( 'notification' , node , 'handling notification' , handleNotification )
15321532 } )
15331533 ws . on ( 'CB:ack,class:message' , ( node : BinaryNode ) => {
15341534 handleBadAck ( node ) . catch ( error => onUnexpectedError ( error , 'handling bad ack' ) )
15351535 } )
15361536
1537- ev . on ( 'call' , ( [ call ] ) => {
1537+ ev . on ( 'call' , async ( [ call ] ) => {
15381538 if ( ! call ) {
15391539 return
15401540 }
@@ -1562,7 +1562,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
15621562 }
15631563
15641564 const protoMsg = proto . WebMessageInfo . fromObject ( msg ) as WAMessage
1565- upsertMessage ( protoMsg , call . offline ? 'append' : 'notify' )
1565+ await upsertMessage ( protoMsg , call . offline ? 'append' : 'notify' )
15661566 }
15671567 } )
15681568
0 commit comments