From 985fdd588460b96c2cde509ef5868c72fbf62d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Garc=C3=ADa?= Date: Fri, 4 Dec 2026 14:08:43 -0300 Subject: [PATCH 1/2] fix(msg): mark deleted conversation messages instead of showing them as live Bump @todoist/comms-sdk to 6.3.1, which keeps the message's deleted flag. msg view and conversation view now show a (deleted) badge and a note, and JSON output has content: null and deleted: true. The comment and message paths share deletedBadge, renderEntryBody and clearDeletedContent. --- package-lock.json | 8 +-- package.json | 2 +- src/commands/comment/view.ts | 10 +-- .../conversation/conversation.test.ts | 68 +++++++++++++++++++ src/commands/conversation/view.ts | 16 +++-- src/commands/msg/msg.test.ts | 30 ++++++++ src/commands/msg/view.ts | 19 ++++-- src/commands/thread/helpers.ts | 9 +-- src/lib/output.ts | 32 +++++---- 9 files changed, 151 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0aef809..dea18c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "dependencies": { "@pnpm/tabtab": "0.5.4", "@todoist/cli-core": "2.1.0", - "@todoist/comms-sdk": "6.2.1", + "@todoist/comms-sdk": "6.3.1", "chalk": "5.6.2", "commander": "14.0.3", "marked": "18.0.3", @@ -2717,9 +2717,9 @@ } }, "node_modules/@todoist/comms-sdk": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/@todoist/comms-sdk/-/comms-sdk-6.2.1.tgz", - "integrity": "sha512-ZQmMEx1v1Nf9X+qbYP2pTGh2+7qbuFmcnHtQbodEg9tjn3jKTcKOJeF1A9E4ZsZ9HenXFyjea6/TDU2lNkRKxA==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/@todoist/comms-sdk/-/comms-sdk-6.3.1.tgz", + "integrity": "sha512-V0UzrPX6QzV+WsAUW35i0re32m4jz1lPLYVHBEzY1fAdVZb4yYp9ehYhCL1S6sG/MrUyd2TmGveW8HRiKtNl8Q==", "license": "MIT", "dependencies": { "@doist/sdk-kmp": "0.6.0", diff --git a/package.json b/package.json index c587483..785fe1e 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "dependencies": { "@pnpm/tabtab": "0.5.4", "@todoist/cli-core": "2.1.0", - "@todoist/comms-sdk": "6.2.1", + "@todoist/comms-sdk": "6.3.1", "chalk": "5.6.2", "commander": "14.0.3", "marked": "18.0.3", diff --git a/src/commands/comment/view.ts b/src/commands/comment/view.ts index c931e14..8634ca5 100644 --- a/src/commands/comment/view.ts +++ b/src/commands/comment/view.ts @@ -1,16 +1,14 @@ -import chalk from 'chalk' import { getCommsClient } from '../../lib/api.js' import { formatRelativeDate } from '../../lib/dates.js' -import { renderMarkdown } from '../../lib/markdown.js' import type { ViewOptions } from '../../lib/options.js' import { clearDeletedContent, colors, - DELETED_COMMENT_TEXT, deletedBadge, formatJson, formatNdjson, pinnedBadge, + renderEntryBody, } from '../../lib/output.js' import { resolveCommentId } from '../../lib/refs.js' @@ -42,10 +40,6 @@ export async function viewComment(ref: string, options: ViewOptions): Promise { }) }) +describe('conversation view with a deleted message', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('marks the deleted message in place, and machine output drops its placeholder content', async () => { + const conversation = createConversation(42, [1], '2026-03-08T10:00:00.000Z') + const base = { + creator: 1, + conversationId: '42', + workspaceId: 1, + posted: new Date('2026-03-08T10:05:00.000Z'), + } + // The API keeps a deleted message, with "-" as its content. + const client = createClient({ + activeConversations: [conversation], + messagesByConversation: { + '42': [ + { ...base, id: '98', content: '-', deleted: true }, + { ...base, id: '99', content: 'Still here', deleted: false }, + ], + }, + }) + apiMocks.getCommsClient.mockResolvedValue(client) + const consoleSpy = captureConsole('log') + + await createProgram().parseAsync(['node', 'tdc', 'conversation', 'view', '42']) + + const lines = consoleSpy.mock.calls.map((call) => String(call[0])) + const deletedHeaders = lines.filter((line) => line.includes('(deleted)')) + expect(deletedHeaders).toHaveLength(1) + expect(deletedHeaders[0]).toContain('id:98') + expect(lines).toContain('This message was deleted.') + expect(lines).not.toContain('-') + expect(lines).toContain('Still here') + + for (const flags of [['--json'], ['--json', '--full']]) { + consoleSpy.mockClear() + await createProgram().parseAsync([ + 'node', + 'tdc', + 'conversation', + 'view', + '42', + ...flags, + ]) + const { messages } = JSON.parse(consoleSpy.mock.calls[0][0]) + expect( + messages.map((m: { id: string; content: string | null; deleted: boolean }) => [ + m.id, + m.content, + m.deleted, + ]), + ).toEqual([ + ['98', null, true], + ['99', 'Still here', false], + ]) + } + + consoleSpy.mockClear() + await createProgram().parseAsync(['node', 'tdc', 'conversation', 'view', '42', '--ndjson']) + const ndjsonMessage = consoleSpy.mock.calls + .map((call) => JSON.parse(String(call[0]))) + .find((line) => line.id === '98') + expect(ndjsonMessage).toMatchObject({ type: 'message', content: null, deleted: true }) + }) +}) + describe('conversation view --pinned', () => { beforeEach(() => { vi.clearAllMocks() diff --git a/src/commands/conversation/view.ts b/src/commands/conversation/view.ts index 770e296..0859513 100644 --- a/src/commands/conversation/view.ts +++ b/src/commands/conversation/view.ts @@ -3,9 +3,15 @@ import chalk from 'chalk' import { getCommsClient } from '../../lib/api.js' import { formatRelativeDate } from '../../lib/dates.js' import { CliError } from '../../lib/errors.js' -import { renderMarkdown } from '../../lib/markdown.js' import { toDate } from '../../lib/options.js' -import { colors, filterEntityFields, pinnedBadge } from '../../lib/output.js' +import { + clearDeletedContent, + colors, + deletedBadge, + filterEntityFields, + pinnedBadge, + renderEntryBody, +} from '../../lib/output.js' import { resolveConversationId } from '../../lib/refs.js' import { buildConversationTitle, type ConversationViewOptions } from './helpers.js' @@ -61,7 +67,7 @@ export async function viewConversation( participantNames: conversation.userIds.map((id) => userMap.get(id)), } const messageOutput = messages.map((m) => ({ - ...m, + ...clearDeletedContent(m), creatorName: userMap.get(m.creator), })) @@ -103,9 +109,9 @@ export async function viewConversation( const author = colors.author(userMap.get(message.creator) || `user:${message.creator}`) const time = colors.timestamp(formatRelativeDate(message.posted)) console.log( - `${author} ${time}${pinnedBadge(message.pinnedDate)} ${colors.timestamp(`id:${message.id}`)}`, + `${author} ${time}${pinnedBadge(message.pinnedDate)}${deletedBadge(message.deleted)} ${colors.timestamp(`id:${message.id}`)}`, ) - console.log(options.raw ? message.content : await renderMarkdown(message.content)) + console.log(await renderEntryBody(message, 'message', options.raw ?? false)) console.log('') } } diff --git a/src/commands/msg/msg.test.ts b/src/commands/msg/msg.test.ts index dae3904..034cc28 100644 --- a/src/commands/msg/msg.test.ts +++ b/src/commands/msg/msg.test.ts @@ -112,6 +112,36 @@ describe('msg view', () => { }) }) +describe('msg view with a deleted message', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('marks the message deleted, and machine output drops its placeholder content', async () => { + const client = createClient() + // The API keeps a deleted message, with "-" as its content. + const deleted = { ...createMessageFixture('200'), content: '-', deleted: true } + client.conversationMessages.getMessage.mockResolvedValue(deleted) + apiMocks.getCommsClient.mockResolvedValue(client) + const consoleSpy = captureConsole('log') + + await createProgram().parseAsync(['node', 'tdc', 'msg', 'view', '200']) + const lines = consoleSpy.mock.calls.map((call) => String(call[0])) + expect(lines[0]).toContain('(deleted)') + expect(lines).toContain('This message was deleted.') + expect(lines).not.toContain('-') + + for (const flags of [['--json'], ['--json', '--full'], ['--ndjson']]) { + consoleSpy.mockClear() + await createProgram().parseAsync(['node', 'tdc', 'msg', 'view', '200', ...flags]) + expect(JSON.parse(consoleSpy.mock.calls[0][0])).toMatchObject({ + content: null, + deleted: true, + }) + } + }) +}) + describe('msg delete', () => { beforeEach(() => { vi.clearAllMocks() diff --git a/src/commands/msg/view.ts b/src/commands/msg/view.ts index 5a7ad88..308891c 100644 --- a/src/commands/msg/view.ts +++ b/src/commands/msg/view.ts @@ -1,8 +1,15 @@ import { getCommsClient } from '../../lib/api.js' import { formatRelativeDate } from '../../lib/dates.js' -import { renderMarkdown } from '../../lib/markdown.js' import type { ViewOptions } from '../../lib/options.js' -import { colors, formatJson, formatNdjson, pinnedBadge } from '../../lib/output.js' +import { + clearDeletedContent, + colors, + deletedBadge, + formatJson, + formatNdjson, + pinnedBadge, + renderEntryBody, +} from '../../lib/output.js' import { resolveMessageId } from '../../lib/refs.js' export async function viewMessage(ref: string, options: ViewOptions): Promise { @@ -17,13 +24,13 @@ export async function viewMessage(ref: string, options: ViewOptions): Promise @@ -25,24 +26,30 @@ export function pinnedBadge(pinnedDate: Date | null | undefined): string { return pinnedDate ? chalk.dim(' (pinned)') : '' } -/** - * Marks a deleted comment in human output. The API keeps deleted comments in place with - * "-" as their content, so they also need {@link DELETED_COMMENT_TEXT} instead of the body. - */ +// The API keeps a deleted comment or message in place, with "-" as its content and +// `deleted: true`. These helpers keep that placeholder out of every output. +type DeletableEntry = { content: string; deleted?: boolean | null } + +/** Marks a deleted comment or message after its header in human output. */ export function deletedBadge(deleted: boolean | null | undefined): string { return deleted ? chalk.dim(' (deleted)') : '' } -export const DELETED_COMMENT_TEXT = 'This comment was deleted.' +/** The body of a comment or message in human output: a note in place of a deleted one's "-". */ +export async function renderEntryBody( + entry: DeletableEntry, + kind: 'comment' | 'message', + raw: boolean, +): Promise { + if (entry.deleted) return chalk.dim(`This ${kind} was deleted.`) + return raw ? entry.content : renderMarkdown(entry.content) +} -/** - * Nulls the content of a deleted comment for JSON output. The API sends "-" as a - * placeholder, which reads like real text; null says there is no content left. - */ -export function clearDeletedContent( - comment: T, +/** Nulls a deleted entry's "-" content for JSON output; null says there is no content left. */ +export function clearDeletedContent( + entry: T, ): Omit & { content: string | null } { - return comment.deleted ? { ...comment, content: null } : comment + return entry.deleted ? { ...entry, content: null } : entry } const THREAD_ESSENTIAL_FIELDS = [ @@ -94,6 +101,7 @@ const MESSAGE_ESSENTIAL_FIELDS = [ 'reactions', 'pinnedDate', 'pinnedBy', + 'deleted', ] as const const WORKSPACE_ESSENTIAL_FIELDS = ['id', 'name', 'creator', 'plan'] as const From 2a3eff0f94505c4dc1bf2b606c524594a9ea6be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Garc=C3=ADa?= Date: Fri, 4 Dec 2026 14:12:35 -0300 Subject: [PATCH 2/2] docs: list the deleted-entry helpers in the output.ts catalog --- CODEBASE.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CODEBASE.md b/CODEBASE.md index b3731fd..b10b21a 100644 --- a/CODEBASE.md +++ b/CODEBASE.md @@ -148,7 +148,10 @@ don't duplicate it here. per-`EntityType` essential-field filtering, `formatError` / `formatErrorJson`, `printJson` / `printNdjson` / `printEmpty`, `colors`, `pluralize`, `closedThreadBadge` (the `(closed)` marker after a thread title), `pinnedBadge` (the - `(pinned)` marker after a pinned comment's or message's time). + `(pinned)` marker after a pinned comment's or message's time), and for deleted comments + and messages `deletedBadge` (the `(deleted)` marker), `renderEntryBody` (the body in + text output, a note in place of the API's `-`) and `clearDeletedContent` (`content: null` + in JSON output). - **`options.ts`** — `ViewOptions`, `PaginatedViewOptions`, `MutationOptions` (extend these rather than adding `json`/`full`/`ndjson` ad hoc). - **`config.ts`** — `~/.config/comms-cli/config.json` I/O over cli-core