Files
outline/server/presenters/comment.ts
Hemachandar fafaddf07f feat: Option to return anchor text for comments (#8196)
* feat: Option to return anchor text for comments

* cleanup anchorText presentation

* consolidated anchor text

* cleanup unused method
2025-01-06 17:13:37 -08:00

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,
};
}