* Keep the first occurrence of each message id. A single `INSERT ... ON * CONFLICT` cannot touch the same conflict target twice, so a repeated id * would otherwise throw.
(messages: PersistedMessage[])
| 10 | * would otherwise throw. |
| 11 | */ |
| 12 | function dedupeById(messages: PersistedMessage[]): PersistedMessage[] { |
| 13 | const seen = new Set<string>() |
| 14 | const out: PersistedMessage[] = [] |
| 15 | for (const m of messages) { |
| 16 | if (seen.has(m.id)) continue |
| 17 | seen.add(m.id) |
| 18 | out.push(m) |
| 19 | } |
| 20 | return out |
| 21 | } |
| 22 | |
| 23 | function toRow( |
| 24 | chatId: string, |
no test coverage detected