(sessionId: string, localId: string)
| 1057 | * also handled. |
| 1058 | */ |
| 1059 | export 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. |
no test coverage detected