refactor(mobile): read a send's not-sent snapshot as a Set

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[].
This commit is contained in:
Brennan Benson
2026-10-04 16:41:26 -07:00
parent e6a1ac069f
commit 5521ec9d69
2 changed files with 10 additions and 11 deletions
@@ -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<string, number>()
const userMessagesByText = new Map<
string,
Array<{ id: string; index: number; unsent: boolean }>
>()
const userMessagesByText = new Map<string, { id: string; index: number; unsent: boolean }[]>()
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)
@@ -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<string>()
// 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