From b89fa3333bdbb7fa264c1c0a4869ac2196b9718a Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 18 Jun 2026 13:00:48 +0800 Subject: [PATCH] refactor(whatsapp): dedupe read receipt helper --- extensions/whatsapp/src/inbound/monitor.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/extensions/whatsapp/src/inbound/monitor.ts b/extensions/whatsapp/src/inbound/monitor.ts index 8b779aab403..90db847a049 100644 --- a/extensions/whatsapp/src/inbound/monitor.ts +++ b/extensions/whatsapp/src/inbound/monitor.ts @@ -845,18 +845,7 @@ export async function attachWebInboxToSocket( } }; - const maybeMarkReadReceiptAfterCompletedDelivery = async ( - inbound: NormalizedInboundMessage, - target: WhatsAppReadReceiptTarget | undefined, - ) => { - if (inbound.access.isSelfChat) { - maybeLogSkippedSelfChatReadReceipt(inbound, target); - return; - } - await maybeMarkInboundAsRead(target); - }; - - const maybeMarkReadReceiptForSkippedAppend = async ( + const maybeMarkNonSelfChatReadReceipt = async ( inbound: NormalizedInboundMessage, target: WhatsAppReadReceiptTarget | undefined, ) => { @@ -921,7 +910,7 @@ export async function attachWebInboxToSocket( const deliveryReadReceipt = inbound.access.isSelfChat ? undefined : readReceipt; if (!stored && shouldSkipStaleAppend(msg, upsertType)) { - await maybeMarkReadReceiptForSkippedAppend(inbound, readReceipt); + await maybeMarkNonSelfChatReadReceipt(inbound, readReceipt); return; } @@ -948,7 +937,7 @@ export async function attachWebInboxToSocket( }, ); if (accepted.kind === "completed") { - await maybeMarkReadReceiptAfterCompletedDelivery( + await maybeMarkNonSelfChatReadReceipt( inbound, accepted.record.metadata?.readReceipt ?? deliveryReadReceipt, ); @@ -973,7 +962,7 @@ export async function attachWebInboxToSocket( const enriched = await enrichInboundMessage(msg); if (!enriched) { await completeUndeliverableDurableInbound(durableId, durableMetadata); - await maybeMarkReadReceiptAfterCompletedDelivery(inbound, deliveryReadReceipt); + await maybeMarkNonSelfChatReadReceipt(inbound, deliveryReadReceipt); return; } @@ -982,7 +971,7 @@ export async function attachWebInboxToSocket( if (dedupeClaim !== "claimed") { if (dedupeClaim === "duplicate") { await completeUndeliverableDurableInbound(durableId, durableMetadata); - await maybeMarkReadReceiptAfterCompletedDelivery(inbound, deliveryReadReceipt); + await maybeMarkNonSelfChatReadReceipt(inbound, deliveryReadReceipt); } return; }