Open History to see the last commit
1import type { ThreadId } from "@t3tools/contracts";
2
3interface TerminalRetentionThread {
4 id: ThreadId;
5 deletedAt: string | null;
6 archivedAt: string | null;
7}
8
9interface CollectActiveTerminalThreadIdsInput {
10 snapshotThreads: readonly TerminalRetentionThread[];
11 draftThreadIds: Iterable<ThreadId>;
12}
13
14export function collectActiveTerminalThreadIds(
15 input: CollectActiveTerminalThreadIdsInput,
16): Set<ThreadId> {
17 const activeThreadIds = new Set<ThreadId>();
18 const snapshotThreadById = new Map(input.snapshotThreads.map((thread) => [thread.id, thread]));
19 for (const thread of input.snapshotThreads) {
20 if (thread.deletedAt !== null) continue;
21 if (thread.archivedAt !== null) continue;
22 activeThreadIds.add(thread.id);
23 }
24 for (const draftThreadId of input.draftThreadIds) {
25 const snapshotThread = snapshotThreadById.get(draftThreadId);
26 if (
27 snapshotThread &&
28 (snapshotThread.deletedAt !== null || snapshotThread.archivedAt !== null)
29 ) {
30 continue;
31 }
32 activeThreadIds.add(draftThreadId);
33 }
34 return activeThreadIds;
35}