Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions apps/mobile/src/features/threads/thread-list-v2-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { canTurnThreadIntoProject, turnThreadIntoProject } from "./turnThreadInt
import { threadCanArchive } from "../home/threadArchive";
import {
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
canMarkThreadUnread,
resolveThreadListV2SnoozeGateExpiryMs,
resolveThreadListV2SnoozeMenuSelection,
resolveThreadListV2SnoozePresets,
Expand Down Expand Up @@ -800,6 +801,20 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {

const visitThread = useAtomCommand(threadEnvironment.visit, { reportFailure: false });
const markThreadUnread = useAtomCommand(threadEnvironment.markUnread, { reportFailure: false });
const canMarkUnread = canMarkThreadUnread(thread, status);
const handleMarkUnread = useCallback(async () => {
if (!canMarkUnread) return;
const result = await markThreadUnread({
environmentId: thread.environmentId,
input: { threadId: thread.id },
});
if (result._tag === "Failure") {
Dialog.alert(
"Could not mark thread unread",
"The thread could not be marked unread. Try again.",
);
}
}, [canMarkUnread, markThreadUnread, thread.environmentId, thread.id]);
const handleAcknowledgeWoke = useCallback(() => {
if (props.wokeAt === null) return;
void visitThread({
Expand Down Expand Up @@ -946,7 +961,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
supported: props.titleRegenerationSupported,
isRegenerating: isRegeneratingTitle,
}),
{ id: "mark-unread", title: "Mark unread", image: "envelope.badge" },
...(canMarkUnread
? [{ id: "mark-unread", title: "Mark unread", image: "envelope.badge" }]
: []),
...(canTurnIntoProject
? [
{
Expand All @@ -958,7 +975,13 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
]
: []),
],
[canTurnIntoProject, props.titleRegenerationSupported, thread.runtime, isRegeneratingTitle],
[
canMarkUnread,
canTurnIntoProject,
props.titleRegenerationSupported,
thread.runtime,
isRegeneratingTitle,
],
);
const menuActions = useMemo<MenuAction[]>(() => {
const nested = Platform.OS === "ios";
Expand Down Expand Up @@ -1060,13 +1083,8 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
if (nativeEvent.event === "archive") handleArchive();
if (nativeEvent.event === "rename") handleRename();
if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
if (nativeEvent.event === "mark-unread") void handleMarkUnread();
if (nativeEvent.event === "turn-into-project") void turnThreadIntoProject(thread);
if (nativeEvent.event === "mark-unread") {
void markThreadUnread({
environmentId: thread.environmentId,
input: { threadId: thread.id },
});
}
if (nativeEvent.event === "copy-thread") {
const target = threadChipCopyTarget(
{ environmentId: thread.environmentId, threadId: thread.id },
Expand Down Expand Up @@ -1104,6 +1122,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
thread,
handleArchive,
handleDelete,
handleMarkUnread,
handleRegenerateTitle,
handleRename,
handleMoveDown,
Expand All @@ -1115,7 +1134,6 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
handleUnpin,
handleUnsettle,
handleUnsnooze,
markThreadUnread,
setCustomSnoozeOpen,
snoozePresets,
props.snoozePresets,
Expand Down
65 changes: 63 additions & 2 deletions apps/mobile/src/features/threads/threadListV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
threadListV2ListItemsAreEqual,
threadListV2RowAccessibilityLabel,
threadHasUnseenCompletion,
canMarkThreadUnread,
type ThreadListV2ListItem,
} from "./threadListV2";

Expand Down Expand Up @@ -114,7 +115,14 @@ describe("layoutThreadListV2RowMenuActions", () => {
direct: actions("new-thread-on-branch", "copy-thread", "copy-thread-id", "settle", "snooze"),
reorder: actions("arrange", "move-up", "move-down"),
pin: actions("unpin"),
secondary: actions("rename", "regenerate-title", "turn-into-project", "archive", "delete"),
secondary: actions(
"rename",
"regenerate-title",
"mark-unread",
"turn-into-project",
"archive",
"delete",
),
};
const flat = layoutThreadListV2RowMenuActions({ ...full, nested: false });
const nested = layoutThreadListV2RowMenuActions({ ...full, nested: true });
Expand All @@ -132,6 +140,7 @@ describe("layoutThreadListV2RowMenuActions", () => {
"more",
]);
expect(nested.at(-1)?.subactions?.map((action) => action.id)).toEqual([
"mark-unread",
"arrange-menu",
"rename",
"regenerate-title",
Expand All @@ -147,7 +156,12 @@ describe("layoutThreadListV2RowMenuActions", () => {
reorder: actions("arrange"),
nested: true,
});
expect(slim.at(-1)?.subactions?.[0]?.id).toBe("arrange");
expect(
slim
.at(-1)
?.subactions?.slice(0, 2)
.map((action) => action.id),
).toEqual(["mark-unread", "arrange"]);
});
});

Expand Down Expand Up @@ -228,6 +242,53 @@ describe("resolveThreadListV2Status", () => {
);
});

describe("canMarkThreadUnread", () => {
const completed = { status: "completed", completedAt: NOW } as const;
it.each([
{
name: "a read completed run",
latestRun: completed,
lastVisitedAt: NOW,
status: "ready",
can: true,
},
{
name: "an unread completed run",
latestRun: completed,
lastVisitedAt: "2026-06-01T00:00:00.000Z",
status: "ready",
can: false,
},
{
name: "no completed run",
latestRun: undefined,
lastVisitedAt: NOW,
status: "ready",
can: false,
},
{
name: "a server without visit tracking",
latestRun: completed,
lastVisitedAt: undefined,
status: "ready",
can: false,
},
{
name: "a working thread",
latestRun: completed,
lastVisitedAt: NOW,
status: "working",
can: false,
},
] as const)("is $can for $name", ({ latestRun, lastVisitedAt, status, can }) => {
const thread = { latestRun, lastVisitedAt } as Pick<
EnvironmentThreadShell,
"latestRun" | "lastVisitedAt"
>;
expect(canMarkThreadUnread(thread, status)).toBe(can);
});
});

describe("threadListV2RowAccessibilityLabel", () => {
const row = {
title: "Fix login",
Expand Down
17 changes: 16 additions & 1 deletion apps/mobile/src/features/threads/threadListV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function layoutThreadListV2RowMenuActions(input: {
if (!input.nested) {
return [...input.direct, ...input.reorder, ...input.pin, ...input.secondary];
}
const markUnread = input.secondary.find((action) => action.id === "mark-unread");
return [
...input.direct,
...input.pin,
Expand All @@ -159,6 +160,7 @@ export function layoutThreadListV2RowMenuActions(input: {
title: "More",
image: "ellipsis.circle",
subactions: [
...(markUnread ? [markUnread] : []),
...(input.reorder.length > 1
? [
{
Expand All @@ -169,7 +171,7 @@ export function layoutThreadListV2RowMenuActions(input: {
},
]
: input.reorder),
...input.secondary,
...input.secondary.filter((action) => action.id !== "mark-unread"),
],
},
];
Expand Down Expand Up @@ -246,6 +248,19 @@ export function threadHasUnseenCompletion(
return completedAtMs > lastVisitedAtMs;
}

/** The server rejects Mark unread without a completed run; older servers cannot persist it. */
export function canMarkThreadUnread(
thread: Pick<EnvironmentThreadShell, "latestRun" | "lastVisitedAt">,
status: ThreadListV2Status,
): boolean {
return (
status === "ready" &&
thread.lastVisitedAt !== undefined &&
thread.latestRun?.completedAt != null &&
!threadHasUnseenCompletion(thread)
);
}

export function resolveThreadListV2WokeAt(
thread: EnvironmentThreadShell,
options: { readonly now: string },
Expand Down
Loading