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
Methods
-
addComment( data = { data.channelId, data.threadId, data.commentId, data.content, data.attributes } ) → Promise
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.Parameters
data : Object
-
Properties
data.channelId : String
The ID of the document or context to which the comment is added.
data.threadId : String
The ID of the comment thread that the comment is added to.
data.commentId : String
The comment ID.
data.content : String
The comment content.
data.attributes : Object
Comment custom attributes.
Returns
Promise
-
getCommentThread( data = { data.channelId, data.threadId } ) → Promise
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 also have the
isFromAdapter
property set totrue
.Parameters
data : Object
-
Properties
data.channelId : String
The ID of the document or context to which the comment is added.
data.threadId : String
The ID of the comment thread that the comment is added to.
Returns
Promise
-
removeComment( data = { data.channelId, data.threadId, data.commentId } ) → Promise
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.
Parameters
data : Object
-
Properties
data.channelId : String
The ID of the document or context that the comment is removed from.
data.threadId : String
The ID of the comment thread that the comment is removed from.
data.commentId : String
The ID of the comment to remove.
Returns
Promise
-
removeCommentThread( data, channelId, threadId ) → Promise
module:comments/comments/commentsrepository~CommentsAdapter#removeCommentThread
Called each time the user removes a comment thread.
Keep in mind that comment thread removal happens only for comment threads created outside of the editor. You do not need to implement this method if you use the comments feature inside the editor only.
It should return a promise that resolves when the thread is removed.
Parameters
data : Object
channelId : String
The ID of the document or context that the comment thread is removed from.
threadId : String
The ID of the thread to remove.
Returns
Promise
-
updateComment( data = { data.channelId, data.threadId, data.commentId, [data.content], [data.attributes] } ) → Promise
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.Parameters
data : Object
-
Properties
data.channelId : String
The ID of the document or context where the comment is updated.
data.threadId : String
The ID of the comment thread where the comment is updated.
data.commentId : String
The ID of the comment to update.
[ data.content ] : String
The new content of the comment.
[ data.attributes ] : Object
Custom comment attributes.
Returns
Promise
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.