Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 202e560

Browse files
t3dotggclaudemaria-rcks
authored
feat(sidebar-v2): thread snoozing (pingdotgg#4311)
Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: maria <[email protected]>
1 parent bb38c33 commit 202e560

34 files changed

Lines changed: 2389 additions & 235 deletions

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ export function HomeScreen(props: HomeScreenProps) {
472472
// boundary is actually crossed while the app stays open (mirrors web);
473473
// without a clock dependency the partition memoizes a frozen "now".
474474
const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
475+
// Snooze wake times are second-precise; a counter bumped exactly at the
476+
// next wake boundary re-runs the partition with a fresh clock so a woken
477+
// thread reappears immediately instead of on the next minute tick.
478+
const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
475479
useEffect(() => {
476480
if (!threadListV2Enabled) return;
477481
// Refresh immediately on enable: the mount-time value can be hours old
@@ -493,8 +497,18 @@ export function HomeScreen(props: HomeScreenProps) {
493497
}
494498
return supported;
495499
}, [serverConfigs]);
500+
const snoozeEnvironmentIds = useMemo(() => {
501+
const supported = new Set<EnvironmentId>();
502+
for (const [environmentId, config] of serverConfigs) {
503+
if (config.environment.capabilities.threadSnooze === true) {
504+
supported.add(environmentId);
505+
}
506+
}
507+
return supported;
508+
}, [serverConfigs]);
496509
const threadListV2Layout = useMemo(() => {
497-
if (!threadListV2Enabled) return { items: [], hiddenSettledCount: 0 };
510+
if (!threadListV2Enabled)
511+
return { items: [], hiddenSettledCount: 0, snoozedCount: 0, nextSnoozeWakeAt: null };
498512
// Settled threads are live shells; archived threads keep their original
499513
// "hidden from lists" meaning.
500514
return buildThreadListV2Items({
@@ -504,20 +518,38 @@ export function HomeScreen(props: HomeScreenProps) {
504518
searchQuery: props.searchQuery,
505519
changeRequestStateByKey,
506520
settlementEnvironmentIds,
521+
snoozeEnvironmentIds,
507522
settledLimit: settledVisibleCount,
508523
now: `${nowMinute}:00.000Z`,
524+
snoozeNow: new Date().toISOString(),
509525
});
510526
}, [
511527
changeRequestStateByKey,
512528
nowMinute,
529+
snoozeWakeTick,
513530
settledVisibleCount,
514531
settlementEnvironmentIds,
532+
snoozeEnvironmentIds,
515533
props.searchQuery,
516534
props.selectedEnvironmentId,
517535
props.threads,
518536
threadListV2Enabled,
519537
v2ScopedProjectGroup,
520538
]);
539+
// Re-partition the moment the earliest snooze expires (clamped to the
540+
// signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
541+
const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
542+
useEffect(() => {
543+
if (nextSnoozeWakeAt === null) return;
544+
const wakeAtMs = Date.parse(nextSnoozeWakeAt);
545+
if (Number.isNaN(wakeAtMs)) return;
546+
const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);
547+
const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);
548+
return () => clearTimeout(id);
549+
// snoozeWakeTick must re-arm the timer even when nextSnoozeWakeAt is
550+
// unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
551+
// range) the boundary string is identical and the chain would die.
552+
}, [nextSnoozeWakeAt, snoozeWakeTick]);
521553
const threadListV2Items = threadListV2Layout.items;
522554

523555
const renderV2Item = useCallback(
@@ -813,11 +845,31 @@ export function HomeScreen(props: HomeScreenProps) {
813845
// Self-contained: v1's listEmpty keys off projectGroups, which ignores the
814846
// v2 project scope, so it can be null (results elsewhere) while this list
815847
// is empty. Search outranks the scope — "No results" names the actionable
816-
// fact when a query is active. Pending tasks render in the header, so the
817-
// list showing them isn't empty in the user's eyes.
848+
// fact when a query is active. Snoozed threads outrank the rest: "No
849+
// threads yet" over an inbox that is merely all-snoozed reads as data
850+
// loss. Pending tasks render in the header, so the list showing them
851+
// isn't empty in the user's eyes.
852+
const v2SnoozedCount = threadListV2Layout.snoozedCount;
818853
const v2ListEmpty =
819854
v2PendingTasks.length > 0 ? null : hasSearchQuery ? (
820-
<EmptyState title="No results" detail={`No threads matching "${props.searchQuery}".`} />
855+
v2SnoozedCount > 0 ? (
856+
// The snoozed threads already passed this search filter: "No
857+
// results" would claim nothing matched when matches are merely
858+
// parked.
859+
<EmptyState
860+
title={
861+
v2SnoozedCount === 1 ? "1 matching thread snoozed" : `All matching threads snoozed`
862+
}
863+
detail={`Threads matching "${props.searchQuery}" are snoozed and return when their wake time passes.`}
864+
/>
865+
) : (
866+
<EmptyState title="No results" detail={`No threads matching "${props.searchQuery}".`} />
867+
)
868+
) : v2SnoozedCount > 0 ? (
869+
<EmptyState
870+
title={v2SnoozedCount === 1 ? "1 thread snoozed" : `${v2SnoozedCount} threads snoozed`}
871+
detail="Snoozed threads return when their wake time passes."
872+
/>
821873
) : v2ScopedProjectGroup !== null ? (
822874
<EmptyState
823875
title={`No threads in ${v2ScopedProjectGroup.title}`}

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ function ThreadNavigationSidebarPane(
399399
// crossed while the pane stays open; without a clock dependency the
400400
// partition memoizes a frozen "now".
401401
const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
402+
// Snooze wake times are second-precise; a counter bumped exactly at the
403+
// next wake boundary re-runs the partition with a fresh clock so a woken
404+
// thread reappears immediately instead of on the next minute tick.
405+
const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
402406
useEffect(() => {
403407
if (!threadListV2Enabled) return;
404408
// Refresh immediately on enable: the mount-time value can be hours old
@@ -420,29 +424,57 @@ function ThreadNavigationSidebarPane(
420424
}
421425
return supported;
422426
}, [serverConfigs]);
427+
const snoozeEnvironmentIds = useMemo(() => {
428+
const supported = new Set<EnvironmentId>();
429+
for (const [environmentId, config] of serverConfigs) {
430+
if (config.environment.capabilities.threadSnooze === true) {
431+
supported.add(environmentId);
432+
}
433+
}
434+
return supported;
435+
}, [serverConfigs]);
423436
const threadListV2Layout = useMemo(() => {
424-
if (!threadListV2Enabled) return { items: [], hiddenSettledCount: 0 };
437+
if (!threadListV2Enabled)
438+
return { items: [], hiddenSettledCount: 0, snoozedCount: 0, nextSnoozeWakeAt: null };
425439
return buildThreadListV2Items({
426440
threads: threads.filter((thread) => thread.archivedAt === null),
427441
environmentId: options.selectedEnvironmentId,
428442
projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
429443
searchQuery: props.searchQuery,
430444
changeRequestStateByKey,
431445
settlementEnvironmentIds,
446+
snoozeEnvironmentIds,
432447
settledLimit: settledVisibleCount,
433448
now: `${nowMinute}:00.000Z`,
449+
snoozeNow: new Date().toISOString(),
434450
});
435451
}, [
436452
changeRequestStateByKey,
437453
nowMinute,
454+
snoozeWakeTick,
438455
options.selectedEnvironmentId,
439456
props.searchQuery,
440457
settledVisibleCount,
441458
settlementEnvironmentIds,
459+
snoozeEnvironmentIds,
442460
threadListV2Enabled,
443461
threads,
444462
selectedProjectScope,
445463
]);
464+
// Re-partition the moment the earliest snooze expires (clamped to the
465+
// signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
466+
const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
467+
useEffect(() => {
468+
if (nextSnoozeWakeAt === null) return;
469+
const wakeAtMs = Date.parse(nextSnoozeWakeAt);
470+
if (Number.isNaN(wakeAtMs)) return;
471+
const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);
472+
const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);
473+
return () => clearTimeout(id);
474+
// snoozeWakeTick must re-arm the timer even when nextSnoozeWakeAt is
475+
// unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
476+
// range) the boundary string is identical and the chain would die.
477+
}, [nextSnoozeWakeAt, snoozeWakeTick]);
446478
const listItems = useMemo<readonly SidebarListItem[]>(() => {
447479
if (!threadListV2Enabled) return listLayout.items;
448480
// Queued offline tasks render above the thread rows (mirrors the
@@ -930,15 +962,28 @@ function ThreadNavigationSidebarPane(
930962
}),
931963
[filterIcon, filterMenu, props.onOpenSettings],
932964
);
965+
// "No threads yet" over an inbox that is merely all-snoozed reads as
966+
// data loss; name the snoozed threads instead.
967+
const snoozedCount = threadListV2Layout.snoozedCount;
933968
const listEmpty = (
934969
<Text className="px-2 py-4 text-sm text-foreground-muted">
935970
{catalogState.isLoadingConnections
936971
? "Loading threads…"
937972
: props.searchQuery.trim().length > 0
938-
? "No matching threads"
939-
: selectedProjectScope !== null
940-
? `No threads in ${selectedProjectScope.title}`
941-
: "No threads yet"}
973+
? snoozedCount > 0
974+
? // Snoozed matches passed this same search filter — "No
975+
// matching threads" would misreport them as nonexistent.
976+
snoozedCount === 1
977+
? "1 matching thread snoozed"
978+
: "All matching threads snoozed"
979+
: "No matching threads"
980+
: snoozedCount > 0
981+
? snoozedCount === 1
982+
? "1 thread snoozed"
983+
: `${snoozedCount} threads snoozed`
984+
: selectedProjectScope !== null
985+
? `No threads in ${selectedProjectScope.title}`
986+
: "No threads yet"}
942987
</Text>
943988
);
944989

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,85 @@ describe("sortThreadsForListV2", () => {
7777
});
7878

7979
describe("buildThreadListV2Items", () => {
80+
it("hides snoozed threads and counts them — visibility parity with web", () => {
81+
const layout = buildThreadListV2Items({
82+
threads: [
83+
makeThread({ id: ThreadId.make("active"), title: "Active" }),
84+
makeThread({
85+
id: ThreadId.make("snoozed"),
86+
title: "Snoozed",
87+
snoozedUntil: "2026-06-03T09:00:00.000Z",
88+
snoozedAt: "2026-06-01T12:00:00.000Z",
89+
}),
90+
makeThread({
91+
id: ThreadId.make("woken"),
92+
title: "Woken",
93+
// Wake time already passed: back in the active list.
94+
snoozedUntil: "2026-06-01T18:00:00.000Z",
95+
snoozedAt: "2026-06-01T12:00:00.000Z",
96+
}),
97+
],
98+
environmentId: null,
99+
searchQuery: "",
100+
now: NOW,
101+
});
102+
103+
// Same createdAt → static sort tiebreaks by id; the point is the woken
104+
// thread is BACK in the card block and the snoozed one is gone.
105+
expect(layout.items.map((item) => item.thread.id)).toEqual(["active", "woken"]);
106+
expect(layout.snoozedCount).toBe(1);
107+
});
108+
109+
it("classifies snooze with the second-precise clock and reports the next wake", () => {
110+
const layout = buildThreadListV2Items({
111+
threads: [
112+
makeThread({
113+
id: ThreadId.make("just-woke"),
114+
title: "Just woke",
115+
// Woke 30s ago: hidden under the minute-floored clock, visible
116+
// under the precise one.
117+
snoozedUntil: "2026-06-02T00:00:30.000Z",
118+
snoozedAt: "2026-06-01T12:00:00.000Z",
119+
}),
120+
makeThread({
121+
id: ThreadId.make("still-snoozed"),
122+
title: "Still snoozed",
123+
snoozedUntil: "2026-06-02T09:00:00.000Z",
124+
snoozedAt: "2026-06-01T12:00:00.000Z",
125+
}),
126+
],
127+
environmentId: null,
128+
searchQuery: "",
129+
// Minute-floored partition clock vs precise snooze clock.
130+
now: "2026-06-02T00:01:00.000Z",
131+
snoozeNow: "2026-06-02T00:01:07.500Z",
132+
});
133+
134+
expect(layout.items.map((item) => item.thread.id)).toEqual(["just-woke"]);
135+
expect(layout.snoozedCount).toBe(1);
136+
expect(layout.nextSnoozeWakeAt).toBe("2026-06-02T09:00:00.000Z");
137+
});
138+
139+
it("keeps snoozed threads visible on environments without the snooze capability", () => {
140+
const layout = buildThreadListV2Items({
141+
threads: [
142+
makeThread({
143+
id: ThreadId.make("snoozed"),
144+
title: "Snoozed",
145+
snoozedUntil: "2026-06-03T09:00:00.000Z",
146+
snoozedAt: "2026-06-01T12:00:00.000Z",
147+
}),
148+
],
149+
environmentId: null,
150+
searchQuery: "",
151+
snoozeEnvironmentIds: new Set(),
152+
now: NOW,
153+
});
154+
155+
expect(layout.items.map((item) => item.thread.id)).toEqual(["snoozed"]);
156+
expect(layout.snoozedCount).toBe(0);
157+
});
158+
80159
it("partitions settled threads into a slim tail with one divider", () => {
81160
const { items } = buildThreadListV2Items({
82161
threads: [

‎apps/mobile/src/features/threads/threadListV2.ts‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effectiveSettled } from "@t3tools/client-runtime/state/thread-settled";
1+
import { effectiveSettled, effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
22
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
33
import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
44

@@ -84,6 +84,13 @@ export interface ThreadListV2Layout {
8484
readonly items: ThreadListV2Item[];
8585
/** Settled threads beyond the render limit (behind "Show more"). */
8686
readonly hiddenSettledCount: number;
87+
/** Snoozed threads hidden from the list (visibility parity with web's
88+
collapsed Snoozed shelf; mobile has no shelf UI yet). */
89+
readonly snoozedCount: number;
90+
/** Soonest wake time among hidden snoozed threads, or null. Callers arm
91+
a timeout at this boundary so the list re-partitions the moment a
92+
snooze expires instead of on the next minute tick. */
93+
readonly nextSnoozeWakeAt: string | null;
8794
}
8895

8996
/**
@@ -106,13 +113,22 @@ export function buildThreadListV2Items(input: {
106113
other environments never classify as settled — the user could neither
107114
un-settle nor pin them. Absent = no gating (tests). */
108115
readonly settlementEnvironmentIds?: ReadonlySet<EnvironmentId>;
116+
/** Environments whose server supports thread.snooze/unsnooze. Same
117+
contract as settlementEnvironmentIds. */
118+
readonly snoozeEnvironmentIds?: ReadonlySet<EnvironmentId>;
109119
readonly autoSettleAfterDays?: number;
110120
/** Max settled rows to render; the rest are counted, not built. */
111121
readonly settledLimit?: number;
112122
/** Injectable for tests; defaults to now. */
113123
readonly now?: string;
124+
/** Second-precise clock for snooze classification. Callers pass a
125+
minute-quantized `now` for memoization; snooze wake times are
126+
second-precise, so classifying with the floored minute would hold a
127+
woken thread hidden for up to a minute. Defaults to `now`. */
128+
readonly snoozeNow?: string;
114129
}): ThreadListV2Layout {
115130
const now = input.now ?? new Date().toISOString();
131+
const snoozeNow = input.snoozeNow ?? now;
116132
const autoSettleAfterDays = input.autoSettleAfterDays ?? 3;
117133
const query = input.searchQuery.trim().toLocaleLowerCase();
118134
const projectKeys = input.projectRefs
@@ -121,6 +137,8 @@ export function buildThreadListV2Items(input: {
121137

122138
const active: EnvironmentThreadShell[] = [];
123139
const settled: EnvironmentThreadShell[] = [];
140+
let snoozedCount = 0;
141+
let nextSnoozeWakeAt: string | null = null;
124142
for (const thread of input.threads) {
125143
// Callers pass live (unarchived) shells; settled threads are among them
126144
// and partition into the tail via effectiveSettled.
@@ -130,8 +148,23 @@ export function buildThreadListV2Items(input: {
130148
}
131149
if (query.length > 0 && !thread.title.toLocaleLowerCase().includes(query)) continue;
132150
const supportsSettlement = input.settlementEnvironmentIds?.has(thread.environmentId) ?? true;
151+
const supportsSnooze = input.snoozeEnvironmentIds?.has(thread.environmentId) ?? true;
133152
const changeRequestState =
134153
input.changeRequestStateByKey?.get(`${thread.environmentId}:${thread.id}`) ?? null;
154+
// Visibility parity with web: a snoozed thread leaves the list until it
155+
// wakes (or raises its hand — effectiveSnoozed refuses blocked/failed
156+
// work). Snooze outranks settled classification, same as web.
157+
if (supportsSnooze && effectiveSnoozed(thread, { now: snoozeNow })) {
158+
snoozedCount += 1;
159+
if (
160+
thread.snoozedUntil != null &&
161+
(nextSnoozeWakeAt === null ||
162+
parseTimestampMs(thread.snoozedUntil) < parseTimestampMs(nextSnoozeWakeAt))
163+
) {
164+
nextSnoozeWakeAt = thread.snoozedUntil;
165+
}
166+
continue;
167+
}
135168
if (
136169
supportsSettlement &&
137170
effectiveSettled(thread, { now, autoSettleAfterDays, changeRequestState })
@@ -168,5 +201,10 @@ export function buildThreadListV2Items(input: {
168201
if (last) {
169202
items[items.length - 1] = { ...last, isLast: true };
170203
}
171-
return { items, hiddenSettledCount: orderedSettled.length - visibleSettled.length };
204+
return {
205+
items,
206+
hiddenSettledCount: orderedSettled.length - visibleSettled.length,
207+
snoozedCount,
208+
nextSnoozeWakeAt,
209+
};
172210
}

‎apps/mobile/src/state/use-thread-selection.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function threadDetailToShell(
6060
archivedAt: thread.archivedAt,
6161
settledOverride: thread.settledOverride,
6262
settledAt: thread.settledAt,
63+
snoozedUntil: thread.snoozedUntil ?? null,
64+
snoozedAt: thread.snoozedAt ?? null,
6365
session: thread.session,
6466
latestUserMessageAt: latestUserMessageAt(thread),
6567
hasPendingApprovals: false,

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const make = Effect.gen(function* () {
141141
repositoryIdentity: true,
142142
connectionProbe: true,
143143
threadSettlement: true,
144+
threadSnooze: true,
144145
...(serverSelfUpdate === null ? {} : { serverSelfUpdate }),
145146
},
146147
};

0 commit comments

Comments
 (0)