Interface

CommentsAdapter (comments/comments)

@ckeditor/ckeditor5-comments/src/comments/commentsrepository

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. To set the adapter, overwrite the CommentsRepository#adapter property.

Filtering

Properties

  • addComment : ( object ) => 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;
  • addCommentThread : ( 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;
    • 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<object>

    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>

    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>

    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>

    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.

  • resolveCommentThread : ( 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;
  • updateComment : ( object ) => 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>;
  • updateCommentThread : ( 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;
    • attributes?: Record<string, any> | null;