mirror of
https://github.com/wassname/talk.git
synced 2026-08-03 13:20:59 +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
@@ -0,0 +1,62 @@
|
||||
import { Db } from "mongodb";
|
||||
|
||||
import { Publisher } from "coral-server/graph/tenant/subscriptions/publisher";
|
||||
import { hasTag } from "coral-server/models/comment";
|
||||
import { Tenant } from "coral-server/models/tenant";
|
||||
import { removeTag } from "coral-server/services/comments";
|
||||
import { moderate } from "coral-server/services/comments/moderation";
|
||||
import { AugmentedRedis } from "coral-server/services/redis";
|
||||
|
||||
import {
|
||||
GQLCOMMENT_STATUS,
|
||||
GQLTAG,
|
||||
} from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
|
||||
import { publishChanges, updateAllCounts } from "./helpers";
|
||||
|
||||
const rejectComment = async (
|
||||
mongo: Db,
|
||||
redis: AugmentedRedis,
|
||||
publisher: Publisher,
|
||||
tenant: Tenant,
|
||||
commentID: string,
|
||||
commentRevisionID: string,
|
||||
moderatorID: string,
|
||||
now: Date
|
||||
) => {
|
||||
// Reject the comment.
|
||||
const result = await moderate(
|
||||
mongo,
|
||||
tenant,
|
||||
{
|
||||
commentID,
|
||||
commentRevisionID,
|
||||
moderatorID,
|
||||
status: GQLCOMMENT_STATUS.REJECTED,
|
||||
},
|
||||
now
|
||||
);
|
||||
|
||||
// Update all the comment counts on stories and users.
|
||||
const counts = await updateAllCounts(mongo, redis, {
|
||||
tenant,
|
||||
...result,
|
||||
});
|
||||
|
||||
// Publish changes to the event publisher.
|
||||
await publishChanges(publisher, {
|
||||
...result,
|
||||
...counts,
|
||||
moderatorID,
|
||||
});
|
||||
|
||||
// If there was a featured tag on this comment, remove it.
|
||||
if (hasTag(result.after, GQLTAG.FEATURED)) {
|
||||
return removeTag(mongo, tenant, result.after.id, GQLTAG.FEATURED);
|
||||
}
|
||||
|
||||
// Return the resulting comment.
|
||||
return result.after;
|
||||
};
|
||||
|
||||
export default rejectComment;
|
||||
Reference in New Issue
Block a user