refactor(whatsapp): dedupe read receipt helper

This commit is contained in:
Vincent Koc
2026-06-18 13:00:48 +08:00
parent d30d409097
commit b89fa3333b

View File

@@ -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;
}