# 댓글

- Human documentation: [https://docs.univer.ai/ko-KR/guides/bases/features/thread-comment](https://docs.univer.ai/ko-KR/guides/bases/features/thread-comment)

- Agent Markdown: [https://docs.univer.ai/ko-KR/guides/bases/features/thread-comment.md](https://docs.univer.ai/ko-KR/guides/bases/features/thread-comment.md)

- Requested language: `ko-KR`

- Content language: `ko-KR`

- Documentation version: `1.0.4`

- Source: [bases/features/thread-comment.ko-KR.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/bases/features/thread-comment.ko-KR.mdx)

---

#### Package metadata

```json
{
  "preset": [],
  "plugins": [
    {
      "client": "@univerjs/thread-comment",
      "facade": "@univerjs/thread-comment/facade"
    },
    {
      "client": "@univerjs/thread-comment-ui",
      "locale": "@univerjs/thread-comment-ui/locale/ko-KR",
      "style": "@univerjs/thread-comment-ui/lib/index.css"
    },
    {
      "client": "@univerjs-pro/bases-thread-comment",
      "facade": "@univerjs-pro/bases-thread-comment/facade"
    },
    {
      "client": "@univerjs-pro/bases-thread-comment-ui",
      "locale": "@univerjs-pro/bases-thread-comment-ui/locale/ko-KR",
      "style": "@univerjs-pro/bases-thread-comment-ui/lib/index.css"
    }
  ],
  "license": true,
  "server": "optional"
}
```

작업, 주문 등의 레코드에 관해 논의할 수 있습니다. 댓글은 그리드, 칸반, 갤러리, 캘린더, 간트 뷰 전반에서 같은 레코드에 연결됩니다. 뷰를 전환해도 별도의 토론이 만들어지지 않습니다.

## 플러그인 등록

Bases 핵심 및 UI 플러그인 뒤에 다음을 추가하세요.

#### npm

```bash
npm install @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

#### pnpm

```bash
pnpm add @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

#### yarn

```bash
yarn add @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

#### bun

```bash
bun add @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

```ts
import { UniverBasesThreadCommentPlugin } from '@univerjs-pro/bases-thread-comment'
import { UniverBasesThreadCommentUIPlugin } from '@univerjs-pro/bases-thread-comment-ui'

import '@univerjs-pro/bases-thread-comment/facade'
import '@univerjs/thread-comment/facade'
import '@univerjs-pro/bases-thread-comment-ui/lib/index.css'

univer.registerPlugin(UniverBasesThreadCommentPlugin)
univer.registerPlugin(UniverBasesThreadCommentUIPlugin)
```

댓글 패키지의 언어 리소스를 병합하고 현재 애플리케이션 사용자를 설정하세요. UI 플러그인은 레코드 댓글 컨트롤을 추가하며, 데이터 플러그인은 댓글을 레코드에 연결합니다.

## 댓글 추가 및 읽기

```ts
const record = univerAPI.getActiveBase()?.getTables()[0]?.getRecords()[0]
if (!record) throw new Error('Create a record first')

await record.createCommentAsync('Please confirm the delivery date.')
const comments = record.getComments()
console.log(comments.map(({ root }) => root.id))
```

`getComments()`는 로컬에 로드된 댓글을 읽습니다. 원격 데이터 소스를 사용하면 `await record.listCommentsAsync()`가 알려진 스레드를 동기화한 후 반환합니다. 답글, 수정, 삭제는 [댓글 Facade](https://docs.univer.ai/ko-KR/reference/facade/thread-comment.md)를 참고하세요.

## 저장 및 공유 토론

로컬 댓글은 `base.save()`를 통해 Base 리소스로 저장할 수 있습니다. 스냅샷을 복원하기 전에 댓글 플러그인을 등록하세요.

공유 토론에는 댓글 서비스, 데이터 소스, 권한도 필요합니다. 문서 공동 편집만으로 댓글이 연결되지는 않습니다. [Office 확장 모듈](https://docs.univer.ai/ko-KR/server/collaboration/extensions.md)을 따르고 두 계정으로 생성, 읽기, 권한, 다시 열기를 테스트하세요.

## 공통 댓글 작업

공통 댓글 Facade와 제품 Facade를 모두 가져오세요. 제품 메서드는 안정적인 앵커를 만들고 공통 API는 답글, 수정, 해결 및 삭제를 처리합니다. `getComments()`는 로컬 상태를 읽습니다. `listCommentsAsync()`는 설정된 데이터 소스를 통해 알려진 스레드를 동기화하며 서버의 모든 스레드를 검색하지 않습니다.

```ts
import '@univerjs/thread-comment/facade'

const [thread] = univerAPI.getComments({ resolved: false })
if (thread) {
  await univerAPI.replyCommentAsync({
    unitId: thread.unitId,
    subUnitId: thread.subUnitId,
    threadId: thread.threadId,
    content: 'Reviewed.',
  })
}
```

## 공유 토론

[Server SDK](https://docs.univer.ai/ko-KR/server/collaboration/extensions.md)로 Comment Service와 Endpoint를 통합하고 협업 및 라이선스를 설정한 뒤 `@univerjs-pro/thread-comment-datasource`의 `UniverThreadCommentDataSourcePlugin`을 등록하세요. 내장 데이터 소스는 `/universer-api/comment/unit/{unitId}/...`와 `/universer-api/user/list`를 사용하므로 앱에서 해당 경로를 제공해야 합니다. 서버는 문서 편집 권한과 별도로 댓글 읽기 및 쓰기 권한을 확인해야 합니다.
