Files
hapi/web/src/lib/suppressed-send-error.ts
T
KorenKritaandGitHub fb3988a81f fix(web): restore failed sends atomically (#1326)
* fix(web): restore failed sends atomically

* fix(web): wait for composer draft hydration

* fix(web): count restored attachments after success

* fix(web): keep scratchlist copy available

* fix(web): move suppressed retry errors to target session
2026-08-03 09:25:01 +08:00

22 lines
916 B
TypeScript

/**
* Moves a retry-suppressed inline send error to the session selected by an
* inactive-session resume. The record stays visible while the retry runs, but
* must follow the eventual mutation target so success/error can resolve it.
*/
export function migrateSuppressedSendError<T extends { restoreSuppressed: boolean }>(
errors: Readonly<Record<string, T>>,
sourceSessionId: string,
resolvedSessionId: string,
): Record<string, T> {
if (sourceSessionId === resolvedSessionId) return errors as Record<string, T>
const source = errors[sourceSessionId]
if (!source?.restoreSuppressed) return errors as Record<string, T>
const next = { ...errors }
delete next[sourceSessionId]
// The retry being resumed is the authoritative in-flight operation, so it
// intentionally supersedes any stale target-session error record.
next[resolvedSessionId] = source
return next
}