[CORL-572] Filter rejected comments from reply counts on user comment history (#2516)

* Filter rejected comments from reply counts on user comment history

CORL-572

* fix: use cache to improve performance

* fix: added TODO
This commit is contained in:
Nick Funk
2019-09-04 12:43:00 -04:00
committed by Kim Gardner
parent aa32fcaea6
commit a696ef9be5
@@ -14,6 +14,7 @@ import * as comment from "coral-server/models/comment";
import {
getLatestRevision,
hasAncestors,
hasPublishedStatus,
} from "coral-server/models/comment/helpers";
import { createConnection } from "coral-server/models/helpers";
import { getCommentEditableUntilDate } from "coral-server/services/comments";
@@ -68,7 +69,18 @@ export const Comment: GQLCommentTypeResolver<comment.Comment> = {
c.childCount > 0
? ctx.loaders.Comments.forParent(c.storyID, c.id, input)
: createConnection(),
replyCount: ({ childCount }) => childCount || 0,
replyCount: async ({ childIDs }, input, ctx) => {
// TODO: (wyattjoh) the childCount should be used eventually, but it should be managed with the status so it's only a count of published comments
if (childIDs.length === 0) {
return 0;
}
const children = await ctx.loaders.Comments.comment.loadMany(childIDs);
return children.reduce(
(sum, c) => (c && hasPublishedStatus(c) ? sum + 1 : sum),
0
);
},
// Action Counts are encoded, decode them for use with the GraphQL system.
actionCounts: c => decodeActionCounts(c.actionCounts),
flags: ({ id }, { first = 10, after }, ctx) =>