MCPcopy Create free account
hub / github.com/tiann/hapi / removeOptimisticMessage

Function removeOptimisticMessage

web/src/lib/message-window-store.ts:1059–1080  ·  view source on GitHub ↗
(sessionId: string, localId: string)

Source from the content-addressed store, hash-verified

1057 * also handled.
1058 */
1059export function removeOptimisticMessage(sessionId: string, localId: string): void {
1060 if (!localId) return
1061 updateState(sessionId, (prev) => {
1062 let changed = false
1063 const filterList = (list: DecryptedMessage[]) => {
1064 const next = list.filter((message) => {
1065 const matchesLocalId = message.localId === localId
1066 const matchesId = message.id === localId
1067 if (matchesLocalId || matchesId) {
1068 changed = true
1069 return false
1070 }
1071 return true
1072 })
1073 return next
1074 }
1075 const messages = filterList(prev.messages)
1076 const pending = filterList(prev.pending)
1077 if (!changed) return prev
1078 return buildState(prev, { messages, pending })
1079 }, true)
1080}
1081
1082/** Transition the queued messages whose localIds match to 'sent' and record invokedAt.
1083 * Driven by the CLI ack (messages-consumed). Unmatched messages remain queued.

Callers 4

handleSyncEventFunction · 0.90
useSendMessageFunction · 0.90
useCancelQueuedMessageFunction · 0.90

Calls 3

updateStateFunction · 0.85
filterListFunction · 0.85
buildStateFunction · 0.85

Tested by

no test coverage detected