mirror of
https://github.com/wassname/talk.git
synced 2026-07-27 11:28:12 +08:00
[CORL-688] Add user comment count tracking (#2744)
* feat: initial impl * Create preliminary comment moderation slices CORL-688 * Move slices logic into stacks CORL-688 * Create user comment counts CORL-688 * Create naive mutation that initializes user comment counts CORL-688 * Use bulk updates in user counts migration CORL-688 * fix: review * fix: fixed issue with aggregation * Migrate creating comment into stacks CORL-688 * Migrate editing a comment to the stacks CORL-688 * Break publishing comment status out of updateAllCounts CORL-688 * review: removed variable scoping in favor of export * revert: feb8e8196cd448f5cd24f1ca2eb0b91fe9bd43c7 * review: simplification of stacks implementation This simplifies the stacks implementation to better reuse code related to count management and event publishing. This can be used to great effect with the upcomming events PR #2738. * fix: check if authorID is null before update user counts CORL-688 Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
This commit is contained in:
committed by
Wyatt Johnson
co-authored by
Wyatt Johnson
parent
0dc3e8968a
commit
e3e2e0f52e
@@ -1,31 +1,32 @@
|
||||
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 { approveComment, rejectComment } from "coral-server/stacks";
|
||||
|
||||
import {
|
||||
GQLApproveCommentInput,
|
||||
GQLRejectCommentInput,
|
||||
GQLTAG,
|
||||
} from "../schema/__generated__/types";
|
||||
|
||||
export const Actions = (ctx: TenantContext) => ({
|
||||
approveComment: (input: GQLApproveCommentInput) =>
|
||||
approve(ctx.mongo, ctx.redis, ctx.publisher, ctx.tenant, {
|
||||
commentID: input.commentID,
|
||||
commentRevisionID: input.commentRevisionID,
|
||||
moderatorID: ctx.user!.id,
|
||||
}),
|
||||
approveComment(
|
||||
ctx.mongo,
|
||||
ctx.redis,
|
||||
ctx.publisher,
|
||||
ctx.tenant,
|
||||
input.commentID,
|
||||
input.commentRevisionID,
|
||||
ctx.user!.id,
|
||||
ctx.now
|
||||
),
|
||||
rejectComment: (input: GQLRejectCommentInput) =>
|
||||
reject(ctx.mongo, ctx.redis, ctx.publisher, ctx.tenant, {
|
||||
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
|
||||
rejectComment(
|
||||
ctx.mongo,
|
||||
ctx.redis,
|
||||
ctx.publisher,
|
||||
ctx.tenant,
|
||||
input.commentID,
|
||||
input.commentRevisionID,
|
||||
ctx.user!.id,
|
||||
ctx.now
|
||||
),
|
||||
});
|
||||
|
||||
@@ -2,6 +2,21 @@ import { ERROR_CODES } from "coral-common/errors";
|
||||
import { ADDITIONAL_DETAILS_MAX_LENGTH } from "coral-common/helpers/validate";
|
||||
import { mapFieldsetToErrorCodes } from "coral-server/graph/common/errors";
|
||||
import TenantContext from "coral-server/graph/tenant/context";
|
||||
import { addTag, removeTag } from "coral-server/services/comments";
|
||||
import {
|
||||
createDontAgree,
|
||||
createFlag,
|
||||
createReaction,
|
||||
removeDontAgree,
|
||||
removeReaction,
|
||||
} from "coral-server/services/comments/actions";
|
||||
import { publishCommentFeatured } from "coral-server/services/events";
|
||||
import {
|
||||
approveComment,
|
||||
createComment,
|
||||
editComment,
|
||||
} from "coral-server/stacks";
|
||||
|
||||
import {
|
||||
GQLCOMMENT_STATUS,
|
||||
GQLCreateCommentDontAgreeInput,
|
||||
@@ -16,22 +31,7 @@ import {
|
||||
GQLTAG,
|
||||
GQLUnfeatureCommentInput,
|
||||
} from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
import {
|
||||
addTag,
|
||||
create,
|
||||
edit,
|
||||
removeTag,
|
||||
} from "coral-server/services/comments";
|
||||
import {
|
||||
createDontAgree,
|
||||
createFlag,
|
||||
createReaction,
|
||||
removeDontAgree,
|
||||
removeReaction,
|
||||
} from "coral-server/services/comments/actions";
|
||||
|
||||
import { approve } from "coral-server/services/comments/moderation";
|
||||
import { publishCommentFeatured } from "coral-server/services/events";
|
||||
import { validateMaximumLength, WithoutMutationID } from "./util";
|
||||
|
||||
export const Comments = (ctx: TenantContext) => ({
|
||||
@@ -41,7 +41,7 @@ export const Comments = (ctx: TenantContext) => ({
|
||||
...comment
|
||||
}: GQLCreateCommentInput | GQLCreateCommentReplyInput) =>
|
||||
mapFieldsetToErrorCodes(
|
||||
create(
|
||||
createComment(
|
||||
ctx.mongo,
|
||||
ctx.redis,
|
||||
ctx.config,
|
||||
@@ -64,7 +64,7 @@ export const Comments = (ctx: TenantContext) => ({
|
||||
),
|
||||
edit: ({ commentID, body }: GQLEditCommentInput) =>
|
||||
mapFieldsetToErrorCodes(
|
||||
edit(
|
||||
editComment(
|
||||
ctx.mongo,
|
||||
ctx.redis,
|
||||
ctx.config,
|
||||
@@ -170,11 +170,16 @@ export const Comments = (ctx: TenantContext) => ({
|
||||
)
|
||||
.then(comment =>
|
||||
comment.status !== GQLCOMMENT_STATUS.APPROVED
|
||||
? approve(ctx.mongo, ctx.redis, ctx.publisher, ctx.tenant, {
|
||||
? approveComment(
|
||||
ctx.mongo,
|
||||
ctx.redis,
|
||||
ctx.publisher,
|
||||
ctx.tenant,
|
||||
commentID,
|
||||
commentRevisionID,
|
||||
moderatorID: ctx.user!.id,
|
||||
})
|
||||
ctx.user!.id,
|
||||
ctx.now
|
||||
)
|
||||
: comment
|
||||
)
|
||||
.then(comment => {
|
||||
|
||||
Reference in New Issue
Block a user