Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): do not reuse archived thread ids as new drafts #7183

Closedmaslinedwin(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/7183/headopened View on GitHub

Showing 7 changed files with 167 additions and 6 deletions (loading 4).

x
0 of 7 viewed, 7 left
35 additions and 0 deletionsapps/web/src/hooks/useHandleNewThread.logic.tsAdded
View file
@@ -0,0 +1,35 @@
+import type { ScopedThreadRef } from "@t3tools/contracts";
+​
+export type StoredDraftReuseDecision = "reuse" | "mint";
+​
+/**
+ * Decide whether a project's stored new-thread draft can keep its thread id.
+ *
+ * An id that already exists in any lifecycle (live, archived, deleted) is
+ * burned. Promoted/sent drafts are never reused, even when both snapshots miss
+ * them. An unloaded archive snapshot is unknown, not absent.
+ */
+export function decideStoredDraftReuse(input: {
+ readonly storedDraftThreadRef: ScopedThreadRef | null;
+ readonly liveShellExists: boolean;
+ readonly archivedShellExists: boolean | null;
+ readonly deletedShellExists?: boolean | null;
+ readonly promoted: boolean;
+}): StoredDraftReuseDecision {
+ if (input.storedDraftThreadRef === null) {
+ return "mint";
+ }
+ if (input.liveShellExists) {
+ return "mint";
+ }
+ if (input.archivedShellExists === true) {
+ return "mint";
+ }
+ if (input.deletedShellExists === true) {
+ return "mint";
+ }