feat(mobile): show when an existing thread has a message waiting in the outbox (#10405)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
66a24d6c1a
commit
d6aa179ad2
14 files changed
+193
-8
No files matched your search
@@ -84,6 +84,7 @@ import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
|
||||
import IconTool from "@tabler/icons-react-native/IconTool";
|
||||
import IconTrash from "@tabler/icons-react-native/IconTrash";
|
||||
import IconTypography from "@tabler/icons-react-native/IconTypography";
|
||||
import IconUpload from "@tabler/icons-react-native/IconUpload";
|
||||
import IconUserCircle from "@tabler/icons-react-native/IconUserCircle";
|
||||
import IconWifiOff from "@tabler/icons-react-native/IconWifiOff";
|
||||
import IconWorld from "@tabler/icons-react-native/IconWorld";
|
||||
@@ -173,6 +174,7 @@ const ANDROID_ICON_BY_SF_SYMBOL: Partial<Record<SFSymbol, Icon>> = {
|
||||
"textformat.size": IconTypography,
|
||||
"textformat.size.larger": IconTextIncrease,
|
||||
"textformat.size.smaller": IconTextDecrease,
|
||||
"tray.and.arrow.up": IconUpload,
|
||||
trash: IconTrash,
|
||||
"wifi.slash": IconWifiOff,
|
||||
xmark: IconX,
|
||||
|
||||
@@ -38,6 +38,7 @@ import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
|
||||
import { usePendingThreadOrder } from "../../state/thread-order";
|
||||
import { environmentServerConfigsAtom } from "../../state/server";
|
||||
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
|
||||
import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
|
||||
import {
|
||||
PendingTaskListRow,
|
||||
ThreadListGroupHeader,
|
||||
@@ -212,6 +213,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
>(() => new Map());
|
||||
const preferencesResult = useAtomValue(mobilePreferencesAtom);
|
||||
const threadListV2Enabled = useThreadListV2Enabled();
|
||||
const queuedThreadKeys = useQueuedThreadKeys();
|
||||
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
|
||||
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
|
||||
const listRef = useRef<LegendListRef | null>(null);
|
||||
@@ -384,6 +386,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
projects: scopedProjects,
|
||||
threads: scopedThreads,
|
||||
pendingTasks: scopedPendingTasks,
|
||||
queuedThreadKeys,
|
||||
environmentId: props.selectedEnvironmentId,
|
||||
searchQuery: props.searchQuery,
|
||||
matchedThreadKeys,
|
||||
@@ -393,6 +396,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
}),
|
||||
[
|
||||
threadListV2Enabled,
|
||||
queuedThreadKeys,
|
||||
props.projectGroupingMode,
|
||||
props.projectSortOrder,
|
||||
props.searchQuery,
|
||||
@@ -655,6 +659,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
now: new Date().toISOString(),
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
queuedThreadKeys,
|
||||
}),
|
||||
});
|
||||
return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
|
||||
@@ -662,6 +667,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
serverConfigs,
|
||||
props.threads,
|
||||
pendingOrder,
|
||||
queuedThreadKeys,
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
nowMinute,
|
||||
@@ -689,6 +695,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
matchedThreadKeys,
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
queuedThreadKeys,
|
||||
settledLimit: settledVisibleCount,
|
||||
now: new Date().toISOString(),
|
||||
snoozedShelfExpanded,
|
||||
@@ -697,6 +704,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
});
|
||||
}, [
|
||||
pendingOrder,
|
||||
queuedThreadKeys,
|
||||
nowMinute,
|
||||
snoozeWakeTick,
|
||||
snoozedShelfExpanded,
|
||||
@@ -818,6 +826,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
<ThreadListV2Row
|
||||
thread={thread}
|
||||
variant={item.item.variant}
|
||||
hasQueuedMessages={queuedThreadKeys.has(movedId)}
|
||||
snoozed={item.item.snoozed}
|
||||
pinned={item.item.pinned}
|
||||
snoozePresetMinute={nowMinute}
|
||||
@@ -883,6 +892,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
activeReorderEnvironmentIds,
|
||||
threadMovePlanners,
|
||||
pendingOrder,
|
||||
queuedThreadKeys,
|
||||
handleMoveThread,
|
||||
handlePinThread,
|
||||
handleRegenerateThreadTitle,
|
||||
@@ -993,6 +1003,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
<ThreadListRow
|
||||
variant="compact"
|
||||
thread={thread}
|
||||
hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
|
||||
environmentLabel={
|
||||
props.savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
|
||||
}
|
||||
@@ -1032,6 +1043,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
handleSwipeableWillOpen,
|
||||
handleRegenerateThreadTitle,
|
||||
machineByEnvironmentId,
|
||||
queuedThreadKeys,
|
||||
props.onArchiveThread,
|
||||
props.onDeletePendingTask,
|
||||
props.onDeleteThread,
|
||||
|
||||
@@ -615,6 +615,43 @@ describe("buildHomeThreadGroups", () => {
|
||||
expect(group?.threads.map((thread) => thread.id)).toEqual(["recent-1", "recent-2", "old"]);
|
||||
});
|
||||
|
||||
it("keeps an old thread in the default view while a message waits in its outbox", () => {
|
||||
const environmentId = EnvironmentId.make("environment-1");
|
||||
const project = makeProject({
|
||||
environmentId,
|
||||
id: ProjectId.make("project-1"),
|
||||
title: "T3 Code",
|
||||
});
|
||||
const threads = [
|
||||
makeThread({
|
||||
environmentId,
|
||||
id: ThreadId.make("recent"),
|
||||
projectId: project.id,
|
||||
title: "Today",
|
||||
updatedAt: "2026-06-28T00:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
environmentId,
|
||||
id: ThreadId.make("old-queued"),
|
||||
projectId: project.id,
|
||||
title: "Two weeks ago, follow-up queued offline",
|
||||
updatedAt: "2026-06-14T00:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
environmentId,
|
||||
id: ThreadId.make("old"),
|
||||
projectId: project.id,
|
||||
title: "Two weeks ago",
|
||||
updatedAt: "2026-06-13T00:00:00.000Z",
|
||||
}),
|
||||
];
|
||||
|
||||
const group = buildGroups([project], threads, {
|
||||
queuedThreadKeys: new Set([`${environmentId}:old-queued`]),
|
||||
})[0];
|
||||
expect(group?.recentThreads.map((thread) => thread.id)).toEqual(["recent", "old-queued"]);
|
||||
});
|
||||
|
||||
it("falls back to the most recent 3 threads when none are within 5 days", () => {
|
||||
const environmentId = EnvironmentId.make("environment-1");
|
||||
const project = makeProject({
|
||||
|
||||
@@ -24,7 +24,7 @@ import * as Arr from "effect/Array";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Order from "effect/Order";
|
||||
|
||||
import { scopedProjectKey } from "../../lib/scopedEntities";
|
||||
import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
|
||||
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
|
||||
|
||||
export type HomeProjectSortOrder = Exclude<SidebarProjectSortOrder, "manual">;
|
||||
@@ -190,10 +190,15 @@ function selectRecentThreads(
|
||||
sortedThreads: ReadonlyArray<EnvironmentThreadShell>,
|
||||
threadSortOrder: SidebarThreadSortOrder,
|
||||
now: number,
|
||||
queuedThreadKeys: ReadonlySet<string> | undefined,
|
||||
): ReadonlyArray<EnvironmentThreadShell> {
|
||||
const cutoff = now - RECENT_THREAD_WINDOW_MS;
|
||||
// A thread with a message waiting in the outbox has work the user is
|
||||
// waiting on, however old its last activity; it never trims away.
|
||||
const recent = sortedThreads.filter(
|
||||
(thread) => getThreadSortTimestamp(thread, threadSortOrder) >= cutoff,
|
||||
(thread) =>
|
||||
getThreadSortTimestamp(thread, threadSortOrder) >= cutoff ||
|
||||
queuedThreadKeys?.has(scopedThreadKey(thread.environmentId, thread.id)) === true,
|
||||
);
|
||||
return recent.length > 0 ? recent : sortedThreads.slice(0, RECENT_THREAD_FALLBACK_COUNT);
|
||||
}
|
||||
@@ -202,6 +207,8 @@ export function buildHomeThreadGroups(input: {
|
||||
readonly projects: ReadonlyArray<EnvironmentProject>;
|
||||
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
|
||||
readonly pendingTasks?: ReadonlyArray<PendingNewTask>;
|
||||
/** Thread keys with a message waiting in the outbox; kept in the default view. */
|
||||
readonly queuedThreadKeys?: ReadonlySet<string>;
|
||||
readonly environmentId: EnvironmentId | null;
|
||||
readonly searchQuery: string;
|
||||
readonly matchedThreadKeys?: ReadonlySet<string>;
|
||||
@@ -326,7 +333,7 @@ export function buildHomeThreadGroups(input: {
|
||||
// only trims the default (no-query) view.
|
||||
const recentThreads =
|
||||
query.length === 0
|
||||
? selectRecentThreads(sortedThreads, input.threadSortOrder, now)
|
||||
? selectRecentThreads(sortedThreads, input.threadSortOrder, now, input.queuedThreadKeys)
|
||||
: sortedThreads;
|
||||
|
||||
// A stale project id still resolves to the canonical member with the same
|
||||
|
||||
@@ -12,6 +12,7 @@ import { pinOrderKeyBetween } from "@t3tools/client-runtime/state/thread-sort";
|
||||
import { appAtomRegistry } from "../../state/atom-registry";
|
||||
import { environmentServerConfigsAtom } from "../../state/server";
|
||||
import { environmentThreadShells, threadEnvironment } from "../../state/threads";
|
||||
import { queuedThreadKeysAtom } from "../../state/use-thread-outbox";
|
||||
import { useAtomCommand } from "../../state/use-atom-command";
|
||||
import { beginPendingThreadOrder, getPendingThreadOrder } from "../../state/thread-order";
|
||||
import { createPendingThreadOrder, createThreadMovePlanner } from "../threads/threadOrder";
|
||||
@@ -480,6 +481,7 @@ export function useThreadListActions(): {
|
||||
threads: shells,
|
||||
section,
|
||||
now: new Date().toISOString(),
|
||||
queuedThreadKeys: appAtomRegistry.get(queuedThreadKeysAtom),
|
||||
settlementEnvironmentIds: new Set(
|
||||
[...configs].flatMap(([id, config]) =>
|
||||
config.environment.capabilities.threadSettlement === true ? [id] : [],
|
||||
|
||||
@@ -33,6 +33,7 @@ import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-pref
|
||||
import { usePendingThreadOrder } from "../../state/thread-order";
|
||||
import { environmentServerConfigsAtom } from "../../state/server";
|
||||
import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
|
||||
import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
|
||||
import { useWorkspaceState } from "../../state/workspace";
|
||||
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
|
||||
import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
|
||||
@@ -165,6 +166,7 @@ function ThreadNavigationSidebarPane(
|
||||
} = useThreadListActions();
|
||||
const threadListV2Enabled = useThreadListV2Enabled();
|
||||
const pendingTasks = usePendingNewTasks();
|
||||
const queuedThreadKeys = useQueuedThreadKeys();
|
||||
const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
|
||||
const environments = useMemo(
|
||||
() =>
|
||||
@@ -313,6 +315,7 @@ function ThreadNavigationSidebarPane(
|
||||
projects: scopedProjects,
|
||||
threads: scopedThreads,
|
||||
pendingTasks: scopedPendingTasks,
|
||||
queuedThreadKeys,
|
||||
environmentId: options.selectedEnvironmentId,
|
||||
searchQuery: props.searchQuery,
|
||||
matchedThreadKeys,
|
||||
@@ -322,6 +325,7 @@ function ThreadNavigationSidebarPane(
|
||||
}),
|
||||
[
|
||||
threadListV2Enabled,
|
||||
queuedThreadKeys,
|
||||
matchedThreadKeys,
|
||||
options,
|
||||
props.searchQuery,
|
||||
@@ -489,6 +493,7 @@ function ThreadNavigationSidebarPane(
|
||||
now: new Date().toISOString(),
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
queuedThreadKeys,
|
||||
}),
|
||||
});
|
||||
return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
|
||||
@@ -496,6 +501,7 @@ function ThreadNavigationSidebarPane(
|
||||
serverConfigs,
|
||||
threads,
|
||||
pendingOrder,
|
||||
queuedThreadKeys,
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
nowMinute,
|
||||
@@ -521,6 +527,7 @@ function ThreadNavigationSidebarPane(
|
||||
matchedThreadKeys,
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
queuedThreadKeys,
|
||||
settledLimit: settledVisibleCount,
|
||||
now: new Date().toISOString(),
|
||||
snoozedShelfExpanded,
|
||||
@@ -529,6 +536,7 @@ function ThreadNavigationSidebarPane(
|
||||
});
|
||||
}, [
|
||||
pendingOrder,
|
||||
queuedThreadKeys,
|
||||
nowMinute,
|
||||
snoozeWakeTick,
|
||||
snoozedShelfExpanded,
|
||||
@@ -884,6 +892,7 @@ function ThreadNavigationSidebarPane(
|
||||
<ThreadListV2Row
|
||||
thread={thread}
|
||||
variant={item.item.variant}
|
||||
hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
|
||||
snoozed={item.item.snoozed}
|
||||
pinned={item.item.pinned}
|
||||
snoozePresetMinute={nowMinute}
|
||||
@@ -1017,6 +1026,7 @@ function ThreadNavigationSidebarPane(
|
||||
<ThreadListRow
|
||||
variant="sidebar"
|
||||
thread={thread}
|
||||
hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
|
||||
environmentLabel={
|
||||
savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
|
||||
}
|
||||
@@ -1061,6 +1071,7 @@ function ThreadNavigationSidebarPane(
|
||||
activeReorderEnvironmentIds,
|
||||
threadMovePlanners,
|
||||
pendingOrder,
|
||||
queuedThreadKeys,
|
||||
confirmDeletePendingTask,
|
||||
confirmDeleteThread,
|
||||
handleSelectThread,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { SymbolView } from "../../components/AppSymbol";
|
||||
|
||||
/** Outbox state is independent of the agent's status, so both stay visible. */
|
||||
export function QueuedMessageIcon({ selected = false }: { readonly selected?: boolean }) {
|
||||
return (
|
||||
<SymbolView
|
||||
name="tray.and.arrow.up"
|
||||
size={12}
|
||||
tintColorClassName={
|
||||
selected ? "accent-user-bubble-foreground-muted" : "accent-foreground-muted"
|
||||
}
|
||||
type="monochrome"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import { useThreadPr, type ThreadPrPresentation } from "../../state/use-thread-p
|
||||
import type { HomeGroupDisplayAction } from "../home/homeListItems";
|
||||
import { ThreadSwipeable } from "../home/thread-swipe-actions";
|
||||
import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
|
||||
import { QueuedMessageIcon } from "./queued-message-icon";
|
||||
import { resolveThreadStatus } from "./threadPresentation";
|
||||
import { ThreadSearchMatchExcerpt } from "./thread-search-match";
|
||||
|
||||
@@ -440,6 +441,8 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
|
||||
readonly thread: EnvironmentThreadShell;
|
||||
readonly environmentLabel: string | null;
|
||||
readonly environmentMachine?: EnvironmentMachineKind;
|
||||
/** A message for this thread is waiting in the outbox. */
|
||||
readonly hasQueuedMessages?: boolean;
|
||||
readonly searchMatch?: EnvironmentThreadSearchMatch;
|
||||
readonly searchQuery?: string;
|
||||
readonly isLast: boolean;
|
||||
@@ -480,7 +483,13 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
|
||||
const timestamp = relativeTime(
|
||||
thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
|
||||
);
|
||||
const threadAccessibilityLabel = pr ? `${thread.title}, ${pr.accessibilityLabel}` : thread.title;
|
||||
const threadAccessibilityLabel = [
|
||||
thread.title,
|
||||
pr?.accessibilityLabel,
|
||||
props.hasQueuedMessages ? "messages queued to send" : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(", ");
|
||||
const subtitleParts = [props.environmentLabel, thread.branch].filter((part): part is string =>
|
||||
Boolean(part),
|
||||
);
|
||||
@@ -611,6 +620,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
|
||||
{thread.title}
|
||||
</Text>
|
||||
<View className="flex-row items-center gap-2">
|
||||
{props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
|
||||
{statusPill}
|
||||
<Text className="text-base tabular-nums text-foreground-tertiary">{timestamp}</Text>
|
||||
<SymbolView
|
||||
@@ -670,6 +680,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
|
||||
{thread.title}
|
||||
</Text>
|
||||
<View className="flex-row items-center gap-2">
|
||||
{props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
|
||||
{statusPill}
|
||||
<Text
|
||||
className={cn(
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
resolveThreadListV2SwipeActions,
|
||||
type ThreadListV2Status,
|
||||
} from "./threadListV2";
|
||||
import { QueuedMessageIcon } from "./queued-message-icon";
|
||||
import { ThreadSearchMatchExcerpt } from "./thread-search-match";
|
||||
|
||||
/**
|
||||
@@ -334,6 +335,8 @@ export const ThreadListV2PendingRow = memo(function ThreadListV2PendingRow(props
|
||||
export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
readonly thread: EnvironmentThreadShell;
|
||||
readonly variant: "card" | "slim";
|
||||
/** A message for this thread is waiting in the outbox. */
|
||||
readonly hasQueuedMessages?: boolean;
|
||||
/** Snoozed-shelf row: shows its wake time and offers Wake. */
|
||||
readonly snoozed?: boolean;
|
||||
/** Pinned-block row: shows the pin glyph and offers Unpin. */
|
||||
@@ -709,6 +712,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
>
|
||||
{props.projectTitle ?? props.project?.title ?? ""}
|
||||
</Text>
|
||||
{props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
|
||||
{pinnedRow ? (
|
||||
<SymbolView
|
||||
name="pin"
|
||||
@@ -830,7 +834,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
variant === "card" ? (
|
||||
<Pressable
|
||||
accessibilityHint={swipeAccessibilityHint}
|
||||
accessibilityLabel={thread.title}
|
||||
accessibilityLabel={
|
||||
props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
|
||||
}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
onPress={() => {
|
||||
@@ -870,7 +876,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
) : (
|
||||
<Pressable
|
||||
accessibilityHint={swipeAccessibilityHint}
|
||||
accessibilityLabel={thread.title}
|
||||
accessibilityLabel={
|
||||
props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
|
||||
}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
className={sidebarPane ? undefined : "bg-screen"}
|
||||
@@ -927,6 +935,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
{props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
|
||||
<Text
|
||||
className={cn(
|
||||
"text-sm tabular-nums",
|
||||
|
||||
@@ -166,6 +166,48 @@ describe("resolveThreadListV2Status", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("queued messages keep a settled thread active", () => {
|
||||
const threads = [
|
||||
makeThread({ id: ThreadId.make("active"), title: "Active" }),
|
||||
makeThread({ id: ThreadId.make("settled"), title: "Settled", settledOverride: "settled" }),
|
||||
makeThread({
|
||||
id: ThreadId.make("settled-queued"),
|
||||
title: "Settled with outbox",
|
||||
settledOverride: "settled",
|
||||
}),
|
||||
];
|
||||
const queuedThreadKeys = new Set([`${environmentId}:settled-queued`]);
|
||||
|
||||
it("lists the thread in the active block instead of the settled shelf", () => {
|
||||
const layout = buildThreadListV2Items({
|
||||
threads,
|
||||
environmentId: null,
|
||||
searchQuery: "",
|
||||
now: NOW,
|
||||
queuedThreadKeys,
|
||||
});
|
||||
expect(layout.items.map((item) => [item.thread.id, item.variant] as const)).toEqual([
|
||||
["active", "card"],
|
||||
["settled-queued", "card"],
|
||||
["settled", "slim"],
|
||||
]);
|
||||
expect(layout.settledCount).toBe(1);
|
||||
});
|
||||
|
||||
it("includes it in the reorderable active section", () => {
|
||||
expect(
|
||||
getThreadListV2OrderedSection({ threads, section: "active", now: NOW, queuedThreadKeys }).map(
|
||||
(thread) => thread.id,
|
||||
),
|
||||
).toEqual(["active", "settled-queued"]);
|
||||
expect(
|
||||
getThreadListV2OrderedSection({ threads, section: "active", now: NOW }).map(
|
||||
(thread) => thread.id,
|
||||
),
|
||||
).toEqual(["active"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveThreadListV2SwipeActions", () => {
|
||||
it("offers settle and snooze for an active snoozable thread", () => {
|
||||
expect(
|
||||
|
||||
@@ -178,12 +178,14 @@ export function getThreadListV2OrderedSection(input: {
|
||||
readonly now: string;
|
||||
readonly settlementEnvironmentIds?: ReadonlySet<EnvironmentId>;
|
||||
readonly snoozeEnvironmentIds?: ReadonlySet<EnvironmentId>;
|
||||
readonly queuedThreadKeys?: ReadonlySet<string>;
|
||||
}): EnvironmentThreadShell[] {
|
||||
const threads = input.threads.filter((thread) => {
|
||||
if (thread.archivedAt !== null) return false;
|
||||
if (
|
||||
(input.settlementEnvironmentIds?.has(thread.environmentId) ?? true) &&
|
||||
thread.settledOverride === "settled"
|
||||
thread.settledOverride === "settled" &&
|
||||
input.queuedThreadKeys?.has(`${thread.environmentId}:${thread.id}`) !== true
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -362,6 +364,10 @@ export function buildThreadListV2Items(input: {
|
||||
/** The selected thread remains visible on an otherwise collapsed shelf so
|
||||
a split-view detail can never lose its navigation row. */
|
||||
readonly selectedThreadKey?: string | null;
|
||||
/** Thread keys (`environmentId:threadId`) with a message waiting in the
|
||||
outbox. Such a thread has work the user is waiting on, so it stays in
|
||||
the active block even when the server has settled it. */
|
||||
readonly queuedThreadKeys?: ReadonlySet<string>;
|
||||
}): ThreadListV2Layout {
|
||||
const now = input.now;
|
||||
const pending =
|
||||
@@ -417,7 +423,9 @@ export function buildThreadListV2Items(input: {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (supportsSettlement && thread.settledOverride === "settled") {
|
||||
const hasQueuedMessages =
|
||||
input.queuedThreadKeys?.has(`${thread.environmentId}:${thread.id}`) === true;
|
||||
if (supportsSettlement && thread.settledOverride === "settled" && !hasQueuedMessages) {
|
||||
settled.push(thread);
|
||||
} else if (thread.pinnedAt != null) {
|
||||
pinned.push(thread);
|
||||
|
||||
@@ -24,6 +24,10 @@ vi.mock("./server", async () => {
|
||||
const { Atom } = await import("effect/unstable/reactivity");
|
||||
return { environmentServerConfigsAtom: Atom.make(new Map()).pipe(Atom.keepAlive) };
|
||||
});
|
||||
vi.mock("./use-thread-outbox", async () => {
|
||||
const { Atom } = await import("effect/unstable/reactivity");
|
||||
return { queuedThreadKeysAtom: Atom.make(new Set<string>()).pipe(Atom.keepAlive) };
|
||||
});
|
||||
|
||||
// The mocked shell source is writable so tests can deliver canonical upserts.
|
||||
const shellsAtom = environmentThreadShells.threadShellsAtom as Atom.Writable<
|
||||
|
||||
@@ -10,6 +10,7 @@ import { getThreadListV2OrderedSection } from "../features/threads/threadListV2"
|
||||
import { appAtomRegistry } from "./atom-registry";
|
||||
import { environmentServerConfigsAtom } from "./server";
|
||||
import { environmentThreadShells } from "./threads";
|
||||
import { queuedThreadKeysAtom } from "./use-thread-outbox";
|
||||
|
||||
export const pendingThreadOrderAtom = Atom.make<PendingThreadOrder | null>(null).pipe(
|
||||
Atom.keepAlive,
|
||||
@@ -50,6 +51,7 @@ export function beginPendingThreadOrder(pending: PendingThreadOrder) {
|
||||
threads: appAtomRegistry.get(environmentThreadShells.threadShellsAtom),
|
||||
section: current.section,
|
||||
now: new Date().toISOString(),
|
||||
queuedThreadKeys: appAtomRegistry.get(queuedThreadKeysAtom),
|
||||
settlementEnvironmentIds: new Set(
|
||||
[...configs].flatMap(([id, config]) =>
|
||||
config.environment.capabilities.threadSettlement === true ? [id] : [],
|
||||
@@ -70,6 +72,7 @@ export function beginPendingThreadOrder(pending: PendingThreadOrder) {
|
||||
unsubscribers.push(
|
||||
appAtomRegistry.subscribe(environmentThreadShells.threadShellsAtom, refresh),
|
||||
appAtomRegistry.subscribe(environmentServerConfigsAtom, refresh),
|
||||
appAtomRegistry.subscribe(queuedThreadKeysAtom, refresh),
|
||||
);
|
||||
return {
|
||||
isPending: () => {
|
||||
|
||||
@@ -58,6 +58,28 @@ export function useThreadOutboxMessages() {
|
||||
return useAtomValue(threadOutboxManager.queuedMessagesByThreadKeyAtom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread keys (`environmentId:threadId`) of existing threads with a message
|
||||
* waiting in the outbox. Creations are excluded: they have no thread row yet
|
||||
* and surface as pending tasks instead. Derived once so list builders and
|
||||
* reorder planners agree on which settled threads are pulled back to active.
|
||||
*/
|
||||
export const queuedThreadKeysAtom = Atom.make((get): ReadonlySet<string> => {
|
||||
const keys = new Set<string>();
|
||||
for (const [threadKey, queue] of Object.entries(
|
||||
get(threadOutboxManager.queuedMessagesByThreadKeyAtom),
|
||||
)) {
|
||||
if (queue.some((message) => message.creation === undefined)) {
|
||||
keys.add(threadKey);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}).pipe(Atom.withLabel("mobile:thread-outbox:queued-thread-keys"));
|
||||
|
||||
export function useQueuedThreadKeys(): ReadonlySet<string> {
|
||||
return useAtomValue(queuedThreadKeysAtom);
|
||||
}
|
||||
|
||||
export function useThreadOutboxShellStatuses() {
|
||||
return useAtomValue(threadOutboxShellStatusesAtom);
|
||||
}
|
||||
Reference in new issue
Block a user