Repository navigation
Add “Mark unread” thread action in sidebar context menu #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { ProjectId, ThreadId } from "@t3tools/contracts"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { reducer, type AppState } from "./store"; | ||
| import { DEFAULT_THREAD_TERMINAL_HEIGHT, DEFAULT_THREAD_TERMINAL_ID, type Thread } from "./types"; | ||
|
|
||
| function makeThread(overrides: Partial<Thread> = {}): Thread { | ||
| return { | ||
| id: ThreadId.makeUnsafe("thread-1"), | ||
| codexThreadId: null, | ||
| projectId: ProjectId.makeUnsafe("project-1"), | ||
| title: "Thread", | ||
| model: "gpt-5-codex", | ||
| terminalOpen: false, | ||
| terminalHeight: DEFAULT_THREAD_TERMINAL_HEIGHT, | ||
| terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | ||
| runningTerminalIds: [], | ||
| activeTerminalId: DEFAULT_THREAD_TERMINAL_ID, | ||
| terminalGroups: [ | ||
| { | ||
| id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | ||
| terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | ||
| }, | ||
| ], | ||
| activeTerminalGroupId: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | ||
| session: null, | ||
| messages: [], | ||
| turnDiffSummaries: [], | ||
| activities: [], | ||
| error: null, | ||
| createdAt: "2026-02-13T00:00:00.000Z", | ||
| branch: null, | ||
| worktreePath: null, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function makeState(thread: Thread): AppState { | ||
| return { | ||
| projects: [ | ||
| { | ||
| id: ProjectId.makeUnsafe("project-1"), | ||
| name: "Project", | ||
| cwd: "/tmp/project", | ||
| model: "gpt-5-codex", | ||
| expanded: true, | ||
| scripts: [], | ||
| }, | ||
| ], | ||
| threads: [thread], | ||
| threadsHydrated: true, | ||
| runtimeMode: "full-access", | ||
| }; | ||
| } | ||
|
|
||
| describe("store reducer", () => { | ||
| it("marks a completed thread as unread by moving lastVisitedAt before completion", () => { | ||
| const latestTurnCompletedAt = "2026-02-25T12:30:00.000Z"; | ||
| const initialState = makeState( | ||
| makeThread({ | ||
| latestTurnCompletedAt, | ||
| lastVisitedAt: "2026-02-25T12:35:00.000Z", | ||
| }), | ||
| ); | ||
|
|
||
| const next = reducer(initialState, { | ||
| type: "MARK_THREAD_UNREAD", | ||
| threadId: ThreadId.makeUnsafe("thread-1"), | ||
| }); | ||
|
|
||
| const updatedThread = next.threads[0]; | ||
| expect(updatedThread).toBeDefined(); | ||
| expect(updatedThread?.lastVisitedAt).toBe("2026-02-25T12:29:59.999Z"); | ||
| expect(Date.parse(updatedThread?.lastVisitedAt ?? "")).toBeLessThan( | ||
| Date.parse(latestTurnCompletedAt), | ||
| ); | ||
| }); | ||
|
|
||
| it("does not change a thread without a completed turn", () => { | ||
| const initialState = makeState( | ||
| makeThread({ | ||
| latestTurnCompletedAt: undefined, | ||
| lastVisitedAt: "2026-02-25T12:35:00.000Z", | ||
| }), | ||
| ); | ||
|
|
||
| const next = reducer(initialState, { | ||
| type: "MARK_THREAD_UNREAD", | ||
| threadId: ThreadId.makeUnsafe("thread-1"), | ||
| }); | ||
|
|
||
| expect(next).toEqual(initialState); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import { | |
| type Action = | ||
| | { type: "SYNC_SERVER_READ_MODEL"; readModel: OrchestrationReadModel } | ||
| | { type: "MARK_THREAD_VISITED"; threadId: ThreadId; visitedAt?: string } | ||
| | { type: "MARK_THREAD_UNREAD"; threadId: ThreadId } | ||
| | { type: "TOGGLE_PROJECT"; projectId: Project["id"] } | ||
| | { type: "TOGGLE_THREAD_TERMINAL"; threadId: ThreadId } | ||
| | { type: "SET_THREAD_TERMINAL_OPEN"; threadId: ThreadId; open: boolean } | ||
|
|
@@ -504,6 +505,29 @@ export function reducer(state: AppState, action: Action): AppState { | |
| }; | ||
| } | ||
|
|
||
| case "MARK_THREAD_UNREAD": { | ||
| return { | ||
| ...state, | ||
| threads: updateThread(state.threads, action.threadId, (thread) => { | ||
| if (!thread.latestTurnCompletedAt) { | ||
| return thread; | ||
| } | ||
| const latestTurnCompletedAtMs = Date.parse(thread.latestTurnCompletedAt); | ||
| if (Number.isNaN(latestTurnCompletedAtMs)) { | ||
| return thread; | ||
| } | ||
| const unreadVisitedAt = new Date(latestTurnCompletedAtMs - 1).toISOString(); | ||
| if (thread.lastVisitedAt === unreadVisitedAt) { | ||
| return thread; | ||
| } | ||
| return { | ||
| ...thread, | ||
| lastVisitedAt: unreadVisitedAt, | ||
| }; | ||
|
Comment on lines
+523
to
+526
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After marking an inactive completed thread unread, refreshing the browser or reopening the desktop app silently clears the marker. This action only changes the in-memory Useful? React with 👍 / 👎. |
||
| }), | ||
| }; | ||
| } | ||
|
|
||
| case "TOGGLE_PROJECT": | ||
| return { | ||
| ...state, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user selects “Mark unread” on the currently open thread,
ChatView.tsximmediately reverses the action: its visited-state effect depends onactiveThread.lastVisitedAtand dispatchesMARK_THREAD_VISITEDwhenever that timestamp precedes completion. Consequently, this menu action cannot mark the active conversation unread, even if the user then navigates away. Coordinate the explicit unread action with that effect so it remains unread until a subsequent visit.Useful? React with 👍 / 👎.