# CommentsAdapter

interface

Comments adapter.

The comments adapter is an object that communicates asynchronously with the data source to fetch or save the comment data. It is used internally by the comments feature whenever a comment is loaded, created or deleted. The adapter is optional. You might need to provide it if you are [using the comments feature without real-time collaboration](../features/collaboration/comments/comments-integration.md). To set the adapter, overwrite the `CommentsRepository#adapter` property.

<a id="properties">

## Properties

<a id="member-addComment">

### `addComment: ( data: Omit<BaseComment, 'isFromAdapter'> & BaseCommentData ) => Promise<object>`

Called each time the user adds a new comment to a thread.

It saves the comment data in the database and returns a promise that should get resolved when the save is completed.

If the promise resolves with an object with the `createdAt` property, the comment property will be updated in the comment in the editor. This is to update the comment data with the server-side information.

The `data` object does not expect the `authorId` property. For security reasons, the author of the comment should be set on the server side.

The `data` object does not expect the `createdAt` property either. You should use the server-side time generator to ensure that all users see the same date.

It is recommended to stringify the `data.attributes` value to JSON and to save it as a string in your database and then to parse the value from JSON when loading comments.

The object which is passed as a parameter can contain the following properties:

* channelId: string | symbol;
* threadId: string;
* commentId: string;
* content: string;
* attributes: Record\<string, any>;

The resolved data object should contain the following properties:

* commentId: string;
* createdAt: Date;

<a id="member-addCommentThread">

### `addCommentThread: ( data: Omit<CommentThreadData, 'isFromAdapter'> & object ) => Promise<object>`

Called whenever a new comment thread is created.

The object which is passed as a parameter can contain the following properties:

* channelId: string | symbol;
* threadId: string;
* context?: [CommentThreadContext](module_comments_comments_commentsrepository-CommentThreadContext.md);
* comments?: Array<[CommentDataJSON](module_comments_comments_commentsrepository-CommentDataJSON.md)>;
* resolvedAt?: Date | null;
* resolvedBy?: string | null;
* attributes?: Record\<string, any> | null;

It should return a promise that resolves with the new comment thread data. The resolved data object should contain the following properties:

* threadId: string;
* comments: Array<{ commentId: string; createdAt: Date; }>;

<a id="member-getCommentThread">

### `getCommentThread: ( data: Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<object | null>`

Called when the editor needs the data for a comment thread.

It should return a promise that resolves with the comment thread data. The resolved data object should contain the following properties:

* threadId: string;
* comments: Array<{ commentId?: string; authorId: string; createdAt: Date; content: string; attributes: Record\<string, any>; }>;
* resolvedAt?: Date | null;
* resolvedBy?: string | null;
* attributes: Record\<string, unknown>;

<a id="member-removeComment">

### `removeComment: ( data: Omit<BaseComment, 'isFromAdapter'> ) => Promise<void>`

Called each time the user removes a comment from the thread.

It removes the comment from the database and returns a promise that will be resolved when the removal is completed.

<a id="member-removeCommentThread">

### `removeCommentThread: ( data: Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<void>`

Called each time the user removes a comment thread.

It should return a promise that resolves when the thread is removed.

<a id="member-reopenCommentThread">

### `reopenCommentThread: ( data: Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<void>`

Called when the user reopens a resolved comment thread.

Should set `resolvedAt` and `resolvedBy` properties to `null` in your database and returns a promise that will be resolved when the operation is completed.

<a id="member-resolveCommentThread">

### `resolveCommentThread: ( data: Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<object>`

Called each time the user resolves a comment thread.

Should set `resolvedAt` and `resolvedBy` properties in your database and should resolve with an object containing these two properties and returns a promise that will be resolved when the operation is completed.

The resolved data object should contain the following properties:

* threadId: string;
* resolvedAt: Date;
* resolvedBy: string;

<a id="member-updateComment">

### `updateComment: ( data: Omit<BaseComment, 'isFromAdapter'> & Partial<BaseCommentData> ) => Promise<void>`

Called each time the user changes the existing comment.

It updates the comment data in the database and returns a promise that will be resolved when the update is completed.

Keep in mind that the `data` parameter only contains the properties of a comment that have changed.

The object which is passed as a parameter can contain the following properties:

* channelId: string | symbol;
* threadId: string;
* commentId: string;
* content?: string;
* attributes?: Record\<string, any>;

<a id="member-updateCommentThread">

### `updateCommentThread: ( data: Omit<UpdateCommentThreadEventData, 'isFromAdapter'> ) => Promise<void>`

Called each time the user changes the existing comment thread.

Keep in mind that for security reasons, the `authorId`, `createdAt`, `resolvedBy` and `resolvedAt` properties are not passed in the `updateCommentThread()` call and you should not set them as a result of this call.

It updates the comment data in the database and returns a promise that will be resolved when the update is completed.

The object which is passed as a parameter can contain the following properties:

* channelId: string | symbol;
* threadId: string;
* context?: [`CommentThreadContext`](module_comments_comments_commentsrepository-CommentThreadContext.md);
* attributes?: Record\<string, any> | null;

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
