Repository navigation
refactor: share the mark-read loop across entities - #145
Conversation
doistbot
left a comment
There was a problem hiding this comment.
This PR extracts the shared mark-read/mark-unread loop from src/commands/thread/helpers.ts into a reusable runReadStateMutation in src/lib/read-state.ts, with threads plugging in via THREAD_READ_STATE — a clean, behavior-preserving refactor that sets up the upcoming conversation mark-read/mark-unread commands. No inline issues were flagged. The review confirmed the thread output, confirmation guards, dry-run handling, JSON rows, and error paths are unchanged, the existing thread tests continue to pin the behavior, the private-channel check still runs during entity load before any mutation, and the new helper is catalogued in CODEBASE.md. One note: static inspection confirmed the structure, but tests and npm run verify weren't run during review, so worth a final green check before merge.
I also left one optional follow-up note in the details below.
Optional follow-up note (1)
src/commands/thread/helpers.ts:101: This re-implements
fetchUnreadThreadsfromsrc/lib/threads.ts, which already callsclient.threads.getUnread(workspaceId)and normalizes the SDK's{ data, version }response into a Map. Building the id →objIndexmap on top of it keeps the normalization in one place:loadUnread: async (client, workspaceId) => new Map([...await fetchUnreadThreads(client, workspaceId)].map(([id, u]) => [id, u.objIndex])).
`tdc thread mark-read` and `mark-unread` ran on a loop in thread/helpers.ts that only knew threads. It now lives in src/lib/read-state.ts as runReadStateMutation, with each entity plugging in how to resolve a ref, load the item and its workspace's unread list, and label it (THREAD_READ_STATE for threads). Conversations can then get the same commands without a second copy of the loop. The thread commands' output, JSON rows and errors are unchanged; their tests pass as they were.
ReadState.lastReadObjIndex held the item's raw entry from the workspace's unread list. For threads the CLI reads that as the last comment read, but a conversation's entry is its first unread message, so the name would mislead there. It is now unreadObjIndex, and each entity's commands say what the index means. No behaviour change.
0a2953b to
ab4623b
Compare
|
🎉 This PR is included in version 6.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
tdc thread mark-readandtdc thread mark-unreadran on a loop insrc/commands/thread/helpers.tsthat only knew about threads: the bulk refs,--stdin, the--yesguard for bulk runs,--dry-run, the per-workspace unread lookup, the per-item messages,--jsonrows and the summary. The PRs above this one addtdc conversation mark-readandmark-unread, which need the same loop.It now lives in
src/lib/read-state.tsasrunReadStateMutation. An entity plugs in throughReadStateEntity: how to resolve a ref, load the item (threads still check the channel is public), fetch its workspace's unread list, and label it.THREAD_READ_STATEinthread/helpers.tsis the thread one, and the messages take the entity's noun, so the thread output is word for word what it was.No behaviour change: the thread mark-read and mark-unread tests pass untouched.
CODEBASE.mdlists the new helper in itssrc/lib/catalogue.