CommentsAdapter (comments/comments)
@ckeditor/ckeditor5-comments/src/comments/commentsrepository
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.
To set the adapter, overwrite the CommentsRepository#adapter
property.
Filtering
Properties
-
addComment : ( object ) => Promise<object>
module:comments/comments/commentsrepository~CommentsAdapter#addComment
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 theauthorId
property. For security reasons, the author of the comment should be set on the server side.The
data
object does not expect thecreatedAt
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;
-
addCommentThread : ( object ) => Promise<object>
module:comments/comments/commentsrepository~CommentsAdapter#addCommentThread
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;
- comments?: Array<CommentDataJSON>;
- 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; }>;
-
getCommentThread : ( Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<null | object>
module:comments/comments/commentsrepository~CommentsAdapter#getCommentThread
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>;
-
removeComment : ( Omit<BaseComment, 'isFromAdapter'> ) => Promise<void>
module:comments/comments/commentsrepository~CommentsAdapter#removeComment
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.
-
removeCommentThread : ( Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<void>
module:comments/comments/commentsrepository~CommentsAdapter#removeCommentThread
Called each time the user removes a comment thread.
It should return a promise that resolves when the thread is removed.
-
reopenCommentThread : ( Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<void>
module:comments/comments/commentsrepository~CommentsAdapter#reopenCommentThread
Called when the user reopens a resolved comment thread.
Should set
resolvedAt
andresolvedBy
properties tonull
in your database and returns a promise that will be resolved when the operation is completed. -
resolveCommentThread : ( Omit<BaseCommentThread, 'isFromAdapter'> ) => Promise<object>
module:comments/comments/commentsrepository~CommentsAdapter#resolveCommentThread
Called each time the user resolves a comment thread.
Should set
resolvedAt
andresolvedBy
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;
-
updateComment : ( object ) => Promise<void>
module:comments/comments/commentsrepository~CommentsAdapter#updateComment
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>;
-
updateCommentThread : ( Omit<UpdateCommentThreadEventData, 'isFromAdapter'> ) => Promise<void>
module:comments/comments/commentsrepository~CommentsAdapter#updateCommentThread
Called each time the user changes the existing comment thread.
Keep in mind that for security reasons, the
authorId
,createdAt
,resolvedBy
andresolvedAt
properties are not passed in theupdateCommentThread()
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
; - attributes?: Record<string, any> | null;
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.