From 5521ec9d699fe4889c250499f3fedcbae33c15a9 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Sun, 4 Oct 2026 16:41:26 -0700 Subject: [PATCH] refactor(mobile): read a send's not-sent snapshot as a Set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit React Doctor flagged the array lookups inside the echo loops and an Array<…> type; the snapshot is read as a Set and the type uses T[]. --- .../session/mobile-native-chat-draft-reconcile.ts | 9 +++------ .../session/mobile-native-chat-pending-retirement.ts | 12 +++++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/mobile/src/session/mobile-native-chat-draft-reconcile.ts b/mobile/src/session/mobile-native-chat-draft-reconcile.ts index c1d0ca054c1..ad85ee008f4 100644 --- a/mobile/src/session/mobile-native-chat-draft-reconcile.ts +++ b/mobile/src/session/mobile-native-chat-draft-reconcile.ts @@ -279,10 +279,7 @@ export function findLandedUnconfirmedSends( // (`[Image: source: …]` or no text) keys under '' so an empty-text send can // claim it. const messageIndexById = new Map() - const userMessagesByText = new Map< - string, - Array<{ id: string; index: number; unsent: boolean }> - >() + const userMessagesByText = new Map() for (const [index, message] of messages.entries()) { messageIndexById.set(message.id, index) if (message.role !== 'user') { @@ -305,14 +302,14 @@ export function findLandedUnconfirmedSends( if (tailIndex === undefined) { continue } - const baselineUnsent = entry.baselineUnsentMessageIds ?? [] + const baselineUnsent = new Set(entry.baselineUnsentMessageIds) const echo = userMessagesByText .get(entry.normalizedText) ?.find( (message) => message.index > tailIndex && !claimedMessageIds.has(message.id) && - !(message.unsent && baselineUnsent.includes(message.id)) + !(message.unsent && baselineUnsent.has(message.id)) ) if (echo) { claimedMessageIds.add(echo.id) diff --git a/mobile/src/session/mobile-native-chat-pending-retirement.ts b/mobile/src/session/mobile-native-chat-pending-retirement.ts index b94c2515bf5..50532a51714 100644 --- a/mobile/src/session/mobile-native-chat-pending-retirement.ts +++ b/mobile/src/session/mobile-native-chat-pending-retirement.ts @@ -160,11 +160,13 @@ export function retireLandedMobileNativeChatPending( } } // A not-sent row settles a send only when it appeared after the send: then it is the send's own. - const landedFor = (item: MobileNativeChatPendingMessage, text: string): number => - (landedCounts.get(text) ?? 0) + - (unsentByText.get(text) ?? []).filter( - (id) => !(item.baselineUnsentMessageIds ?? []).includes(id) - ).length + const landedFor = (item: MobileNativeChatPendingMessage, text: string): number => { + const baselineUnsent = new Set(item.baselineUnsentMessageIds) + return ( + (landedCounts.get(text) ?? 0) + + (unsentByText.get(text) ?? []).filter((id) => !baselineUnsent.has(id)).length + ) + } const landedPendingIds = new Set() // Why a separate set: a barrier preserves adjacency after a landing consumed a whole // row. An image landing can share its row with the send glued after it, so treating it