mirror of
https://github.com/outline/outline.git
synced 2026-02-21 11:59:06 -06:00
* feat: Option to return anchor text for comments * cleanup anchorText presentation * consolidated anchor text * cleanup unused method
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
|
import { Comment } from "@server/models";
|
|
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
|
import presentUser from "./user";
|
|
|
|
type Options = {
|
|
/** Whether to include anchor text, if it exists */
|
|
includeAnchorText?: boolean;
|
|
};
|
|
|
|
export default function present(
|
|
comment: Comment,
|
|
{ includeAnchorText }: Options = {}
|
|
) {
|
|
let anchorText: string | undefined;
|
|
|
|
if (includeAnchorText && comment.document) {
|
|
const commentMarks = ProsemirrorHelper.getComments(
|
|
DocumentHelper.toProsemirror(comment.document)
|
|
);
|
|
anchorText = ProsemirrorHelper.getAnchorTextForComment(
|
|
commentMarks,
|
|
comment.id
|
|
);
|
|
}
|
|
|
|
return {
|
|
id: comment.id,
|
|
data: comment.data,
|
|
documentId: comment.documentId,
|
|
parentCommentId: comment.parentCommentId,
|
|
createdBy: presentUser(comment.createdBy),
|
|
createdById: comment.createdById,
|
|
resolvedAt: comment.resolvedAt,
|
|
resolvedBy: comment.resolvedBy ? presentUser(comment.resolvedBy) : null,
|
|
resolvedById: comment.resolvedById,
|
|
createdAt: comment.createdAt,
|
|
updatedAt: comment.updatedAt,
|
|
reactions: comment.reactions ?? [],
|
|
anchorText,
|
|
};
|
|
}
|