-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmutate.ts
More file actions
28 lines (22 loc) · 946 Bytes
/
mutate.ts
File metadata and controls
28 lines (22 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { getTwistClient } from '../../lib/api.js'
import type { MutationOptions } from '../../lib/options.js'
import { formatJson } from '../../lib/output.js'
import { assertChannelIsPublic } from '../../lib/public-channels.js'
import { resolveThreadId } from '../../lib/refs.js'
type DoneOptions = MutationOptions
export async function markThreadDone(ref: string, options: DoneOptions): Promise<void> {
const threadId = resolveThreadId(ref)
if (options.dryRun) {
console.log(`Dry run: would archive thread ${threadId}`)
return
}
const client = await getTwistClient()
const thread = await client.threads.getThread(threadId)
await assertChannelIsPublic(thread.channelId, thread.workspaceId)
await client.inbox.archiveThread(threadId)
if (options.json) {
console.log(formatJson({ id: threadId, isArchived: true }))
return
}
console.log(`Thread ${threadId} archived.`)
}