Stores the comments on dumps, threaded by parent_id. The comment routes call it and broadcast what it returns. It leaves checking that the caller may see the dump to them.

Functions

f
createComment(
dumpId: string,
userId: string,
body: string,
parentId?: string
): Comment

Posts a comment on dump dumpId, replying to parentId if given, for POST /api/dumps/:dumpId/comments. It notifies the dump's poster and the users it mentions, unless the dump is private, and links the comment's attachments and backlinks. The route has checked that the caller may see the dump.

f
deleteComment(
commentId: string,
requestingUserId: string,
canModerate: boolean
): CommentDump

Deletes a comment, for DELETE /api/comments/:commentId. canModerate lets someone other than the author do it. The body is emptied and the backlinks dropped, but the row stays so its replies keep their place. The route broadcasts the deletion to those who may see the returned dump.

f
getCommentDumpId(commentId: string): string

Returns the id of the dump comment commentId is posted under. The likers route uses it to check that the caller may see that dump.

f
getComments(dumpId: string): Comment[]

Returns every comment on dump dumpId, oldest first, for GET /api/dumps/:dumpId/comments. Deleted comments are included, emptied, so the client can keep their replies in place.

f
updateComment(
commentId: string,
body: string,
requestingUserId: string,
canModerate: boolean
): { comment: Comment; dump: CommentDump; }

Replaces a comment's body, for PATCH /api/comments/:commentId. canModerate lets someone other than the author do it. It notifies, in the author's name, the users it mentions for the first time, unless the dump is private, and relinks the attachments and backlinks. The route broadcasts the comment to those who may see its dump.

Interfaces

I
CommentDump

The dump a comment is on, as updateComment and deleteComment return it: what the route needs to choose the broadcast's audience.