Files
orca/src/shared/returned-draft-text.ts
T
Brennan Benson b354aab18e fix(mobile-chat): a failed message's text is added to the draft, and an expired resend no longer blocks that text (#25149)
* fix(mobile-chat): a returned message is appended to the draft, and an expired resend id is spent

* test(mobile-chat): leave the idempotent append to the shared rule's own test

* docs(native-chat): say a whitespace-only draft counts as empty

* docs(mobile-chat): don't overclaim where returned text survives
2026-10-05 11:37:26 -07:00

20 lines
645 B
TypeScript

/**
* Puts text a chat handed back after what the composer already holds, a blank line apart. It never
* replaces typed text (a whitespace-only draft counts as empty), and adds nothing when the draft
* already ends with that text, so handing the same text back twice leaves one copy.
*/
export function appendReturnedDraftText(draft: string, text: string): string {
const returned = text.trimEnd()
if (returned.trim() === '') {
return draft
}
const kept = draft.trimEnd()
if (kept === '') {
return text
}
if (kept === returned || kept.endsWith(`\n\n${returned}`)) {
return draft
}
return `${kept}\n\n${text}`
}