mirror of
https://github.com/wassname/talk.git
synced 2026-08-02 13:10:23 +08:00
Un-feature a comment when it is rejected (#2555)
Also decrements the featured count for the story if rejected using the in-stream moderation. CORL-554
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import TenantContext from "coral-server/graph/tenant/context";
|
||||
import { hasTag } from "coral-server/models/comment";
|
||||
import { removeTag } from "coral-server/services/comments";
|
||||
import { approve, reject } from "coral-server/services/comments/moderation";
|
||||
import {
|
||||
GQLApproveCommentInput,
|
||||
GQLRejectCommentInput,
|
||||
GQLTAG,
|
||||
} from "../schema/__generated__/types";
|
||||
|
||||
export const Actions = (ctx: TenantContext) => ({
|
||||
@@ -17,5 +20,12 @@ export const Actions = (ctx: TenantContext) => ({
|
||||
commentID: input.commentID,
|
||||
commentRevisionID: input.commentRevisionID,
|
||||
moderatorID: ctx.user!.id,
|
||||
}),
|
||||
}).then(comment =>
|
||||
// if a comment was previously featured
|
||||
// and is now rejected, we need to remove the
|
||||
// featured tag
|
||||
hasTag(comment, GQLTAG.FEATURED)
|
||||
? removeTag(ctx.mongo, ctx.tenant, comment.id, GQLTAG.FEATURED)
|
||||
: comment
|
||||
),
|
||||
});
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { GQLCOMMENT_STATUS } from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
import {
|
||||
GQLCOMMENT_STATUS,
|
||||
GQLTAG,
|
||||
} from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
|
||||
import { Comment } from "./comment";
|
||||
import { MODERATOR_STATUSES, PUBLISHED_STATUSES } from "./constants";
|
||||
@@ -73,3 +76,7 @@ export function calculateRejectionRate(counts: CommentStatusCounts): number {
|
||||
|
||||
return rejected / (published + rejected);
|
||||
}
|
||||
|
||||
export function hasTag(comment: Pick<Comment, "tags">, tag: GQLTAG) {
|
||||
return comment.tags.some(v => v.type === tag);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user