# Thread Comment

- Human documentation: [https://docs.univer.ai/reference/facade/thread-comment](https://docs.univer.ai/reference/facade/thread-comment)

- Agent Markdown: [https://docs.univer.ai/reference/facade/thread-comment.md](https://docs.univer.ai/reference/facade/thread-comment.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/thread-comment.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/thread-comment.mdx)

---

| Packages | `@univerjs/thread-comment`, `@univerjs/docs-thread-comment`, `@univerjs/sheets-thread-comment`, `@univerjs-pro/bases-thread-comment`, `@univerjs-pro/boards-thread-comment`, `@univerjs-pro/slides-thread-comment`, `@univerjs-pro/shape-thread-comment` |
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

A unified Facade for creating, querying, updating, resolving, and deleting thread comments across Univer products. The existing Sheets comment object and builder APIs remain documented below.

## Cross-product API

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

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

| Method                | Purpose                                                |
| --------------------- | ------------------------------------------------------ |
| `createCommentAsync`  | Create a root thread on a serialized product anchor    |
| `replyCommentAsync`   | Reply to a loaded root thread                          |
| `updateCommentAsync`  | Update root or reply content and attachments           |
| `deleteCommentAsync`  | Delete one comment or the complete thread tree         |
| `resolveCommentAsync` | Resolve or reopen a thread                             |
| `getComments`         | Filter locally loaded threads                          |
| `listCommentsAsync`   | Synchronize known threads, then apply the same filters |

Available anchor kinds are `SHEET_CELL`, `SHEET_DRAWING`, `DOC_TEXT_RANGE`, `DOC_DRAWING`, `SLIDE_ELEMENT`, `SLIDE_POSITION`, `BOARD_ELEMENT`, `BOARD_POSITION`, and `BASE_RECORD` through `univerAPI.Enum.ThreadCommentAnchorKind`.

Product Facade entries provide convenient methods on ranges, text ranges, elements, slides, boards, and Base records. Use the root methods when an application already owns the serialized anchor.

## Legacy Sheets comment objects

### @univerjs/sheets-thread-comment

| Method                              | Description                           |
| ----------------------------------- | ------------------------------------- |
| [`build`](#build)                   | Build the comment                     |
| [`copy`](#copy)                     | Copy the comment                      |
| [`create`](#create)                 | Create a new FTheadCommentItem        |
| [`deleteAsync`](#deleteasync)       | Delete the comment and its replies    |
| [`getCommentData`](#getcommentdata) | Get the comment data                  |
| [`getIsRoot`](#getisroot)           | Whether the comment is a root comment |
| [`getRange`](#getrange)             | Get the range of the comment          |
| [`getReplies`](#getreplies)         | Get the replies of the comment        |
| [`getRichText`](#getrichtext)       | Get the rich text of the comment      |
| [`replyAsync`](#replyasync)         | Reply to the comment                  |
| [`resolveAsync`](#resolveasync)     | Resolve the comment                   |
| [`setContent`](#setcontent)         | Set the content of the comment        |
| [`setDateTime`](#setdatetime)       | Set the date time of the comment      |
| [`setId`](#setid)                   | Set the id of the comment             |
| [`setPersonId`](#setpersonid)       | Set the person id of the comment      |
| [`setThreadId`](#setthreadid)       | Set the thread id of the comment      |
| [`updateAsync`](#updateasync)       | Update the comment content            |

## APIs

### Lifecycle & Creation

### `build`

Build the comment

**Signature**

```typescript
build(): IThreadComment
```

**Returns**

* `IThreadComment` — The comment

**Examples**

```ts
const richText = univerAPI.newRichText().insertText('hello univer');
const comment = univerAPI.newTheadComment()
  .setContent(richText)
  .setPersonId('mock-user-id')
  .setDateTime(new Date('2025-02-21 14:22:22'))
  .setId('mock-comment-id')
  .setThreadId('mock-thread-id')
  .build();
console.log(comment);
```

Source: 

`@univerjs/sheets-thread-comment`

### `create`

Create a new FTheadCommentItem

**Signature**

```typescript
static create(comment?: IThreadComment): FTheadCommentItem
```

**Parameters**

* `comment` `IThreadComment` *(optional)* — *No description*

**Returns**

* `FTheadCommentItem` — A new instance of FTheadCommentItem

**Examples**

```ts
const commentBuilder = univerAPI.newTheadComment();
console.log(commentBuilder);
```

Source: 

`@univerjs/sheets-thread-comment`

### Getters & Queries

### `getCommentData`

Get the comment data

**Signature**

```typescript
getCommentData(): IBaseComment
```

**Returns**

* `IBaseComment` — The comment data

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
  console.log(comment.getCommentData());
});
```

Source: 

`@univerjs/sheets-thread-comment`

### `getIsRoot`

Whether the comment is a root comment

**Signature**

```typescript
getIsRoot(): boolean
```

**Returns**

* `boolean` — Whether the comment is a root comment

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
  console.log(comment.getIsRoot());
});
```

Source: 

`@univerjs/sheets-thread-comment`

### `getRange`

Get the range of the comment

**Signature**

```typescript
getRange(): FRange | null
```

**Returns**

* `FRange | null` — The range of the comment

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
  const range = comment.getRange();
  if (range) {
    console.log(range.getA1Notation());
  }
});
```

Source: 

`@univerjs/sheets-thread-comment`

### `getReplies`

Get the replies of the comment

**Signature**

```typescript
getReplies(): FThreadComment[] | undefined
```

**Returns**

* `FThreadComment[]` — the replies of the comment

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
  if (comment.getIsRoot()) {
    const replies = comment.getReplies();
    replies?.forEach((reply) => {
      console.log(reply.getCommentData());
    });
  }
});
```

Source: 

`@univerjs/sheets-thread-comment`

### `getRichText`

Get the rich text of the comment

**Signature**

```typescript
getRichText(): RichTextValue
```

**Returns**

* `RichTextValue` — The rich text of the comment

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();
comments.forEach((comment) => {
  console.log(comment.getRichText());
});
```

Source: 

`@univerjs/sheets-thread-comment`

### Setters & Modifiers

### `setContent`

Set the content of the comment

**Signature**

```typescript
setContent(content: IDocumentBody | RichTextValue): FTheadCommentBuilder
```

**Parameters**

* `content` `IDocumentBody | RichTextValue` — *No description*

**Returns**

* `FTheadCommentBuilder` — The comment builder for chaining

**Examples**

```ts
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText);
console.log(commentBuilder.content);

// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);
```

Source: 

`@univerjs/sheets-thread-comment`

### `setDateTime`

Set the date time of the comment

**Signature**

```typescript
setDateTime(date: Date): FTheadCommentBuilder
```

**Parameters**

* `date` `Date` — *No description*

**Returns**

* `FTheadCommentBuilder` — The comment builder for chaining

**Examples**

```ts
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText)
  .setDateTime(new Date('2025-02-21 14:22:22'));
console.log(commentBuilder.dateTime);

// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);
```

Source: 

`@univerjs/sheets-thread-comment`

### `setId`

Set the id of the comment

**Signature**

```typescript
setId(id: string): FTheadCommentBuilder
```

**Parameters**

* `id` `string` — *No description*

**Returns**

* `FTheadCommentBuilder` — The comment builder for chaining

**Examples**

```ts
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText)
  .setId('mock-comment-id');
console.log(commentBuilder.id);

// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);
```

Source: 

`@univerjs/sheets-thread-comment`

### `setPersonId`

Set the person id of the comment

**Signature**

```typescript
setPersonId(userId: string): FTheadCommentBuilder
```

**Parameters**

* `userId` `string` — *No description*

**Returns**

* `FTheadCommentBuilder` — The comment builder for chaining

**Examples**

```ts
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText)
  .setPersonId('mock-user-id');
console.log(commentBuilder.personId);

// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);
```

Source: 

`@univerjs/sheets-thread-comment`

### `setThreadId`

Set the thread id of the comment

**Signature**

```typescript
setThreadId(threadId: string): FTheadCommentBuilder
```

**Parameters**

* `threadId` `string` — *No description*

**Returns**

* `FTheadCommentBuilder` — The comment builder

**Examples**

```ts
// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText)
  .setThreadId('mock-thread-id');
console.log(commentBuilder.threadId);

// Add the comment to the cell A1
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const cell = fWorksheet.getRange('A1');
const result = await cell.addCommentAsync(commentBuilder);
console.log(result);
```

Source: 

`@univerjs/sheets-thread-comment`

### `updateAsync`

Update the comment content

**Signature**

```typescript
async updateAsync(content: IDocumentBody | RichTextValue): Promise<boolean>
```

**Parameters**

* `content` `IDocumentBody | RichTextValue` — *No description*

**Returns**

* `Promise<boolean>` — Whether the comment is updated successfully

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText)
  .setId('mock-comment-id');
const cell = fWorksheet.getRange('A1');
await cell.addCommentAsync(commentBuilder);

// Update the comment after 3 seconds
setTimeout(async () => {
  const comment = fWorksheet.getCommentById('mock-comment-id');
  const newRichText = univerAPI.newRichText().insertText('Hello Univer AI');
  const result = await comment.updateAsync(newRichText);
  console.log(result);
}, 3000);
```

Source: 

`@univerjs/sheets-thread-comment`

### Actions & Operations

### `copy`

Copy the comment

**Signature**

```typescript
copy(): FTheadCommentBuilder
```

**Returns**

* `FTheadCommentBuilder` — The comment builder

**Examples**

```ts
const commentBuilder = univerAPI.newTheadComment();
const newCommentBuilder = commentBuilder.copy();
console.log(newCommentBuilder);
```

Source: 

`@univerjs/sheets-thread-comment`

### `deleteAsync`

Delete the comment and its replies

**Signature**

```typescript
deleteAsync(): Promise<boolean>
```

**Returns**

* `Promise<boolean>` — Whether the comment is deleted successfully

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const comments = fWorksheet.getComments();

// Delete the first comment
const result = await comments[0]?.deleteAsync();
console.log(result);
```

Source: 

`@univerjs/sheets-thread-comment`

### Miscellaneous

### `replyAsync`

Reply to the comment

**Signature**

```typescript
replyAsync(comment: FTheadCommentBuilder): Promise<boolean>
```

**Parameters**

* `comment` `FTheadCommentBuilder` — *No description*

**Returns**

* `Promise<boolean>` — Whether the comment is replied successfully

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText)
  .setId('mock-comment-id');
const cell = fWorksheet.getRange('A1');
await cell.addCommentAsync(commentBuilder);

// Reply to the comment
const replyText = univerAPI.newRichText().insertText('Hello Univer AI');
const reply = univerAPI.newTheadComment().setContent(replyText);
const comment = fWorksheet.getCommentById('mock-comment-id');
const result = await comment.replyAsync(reply);
console.log(result);
```

Source: 

`@univerjs/sheets-thread-comment`

### `resolveAsync`

Resolve the comment

**Signature**

```typescript
resolveAsync(resolved?: boolean): Promise<boolean>
```

**Parameters**

* `resolved` `boolean` *(optional)* — *No description*

**Returns**

* `Promise<boolean>` — Set the comment to resolved or not operation result

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a new comment
const richText = univerAPI.newRichText().insertText('hello univer');
const commentBuilder = univerAPI.newTheadComment()
  .setContent(richText)
  .setId('mock-comment-id');
const cell = fWorksheet.getRange('A1');
await cell.addCommentAsync(commentBuilder);

// Resolve the comment after 3 seconds
setTimeout(async () => {
  const comment = fWorksheet.getCommentById('mock-comment-id');
  const result = await comment.resolveAsync(true);
  console.log(result);
}, 3000);
```

Source: 

`@univerjs/sheets-thread-comment`
