[CORL-181] Comment Count Injection (#2581)

* feat: inject comment counts

* fix: tests

* feat: integrate stream embed with coral counts

* chore: refactor constants

* test: test for count bundle

* test: test live comment count integration with stream embed

* feat: use defer

* fix: snapshot

* feat: auto add count.js in when calling Coral.createStreamEmbed

* fix: tests

* fix: rm duplicate test

* chore: remove unuse file
This commit is contained in:
Vinh
2019-10-01 19:22:15 +00:00
committed by Wyatt Johnson
parent 53fa5f43e5
commit 808b355a27
48 changed files with 888 additions and 50 deletions
+2 -4
View File
@@ -3,6 +3,7 @@ import {
GQLTAG,
} from "coral-server/graph/tenant/schema/__generated__/types";
import { calculateTotalPublishedCommentCount } from "../story";
import { Comment } from "./comment";
import { MODERATOR_STATUSES, PUBLISHED_STATUSES } from "./constants";
import { Revision } from "./revision";
@@ -68,10 +69,7 @@ export function createEmptyCommentStatusCounts(): CommentStatusCounts {
}
export function calculateRejectionRate(counts: CommentStatusCounts): number {
const published = PUBLISHED_STATUSES.reduce(
(acc, status) => counts[status] + acc,
0
);
const published = calculateTotalPublishedCommentCount(counts);
const rejected = counts[GQLCOMMENT_STATUS.REJECTED];
return rejected / (published + rejected);
@@ -9,6 +9,7 @@ import { dotize } from "coral-common/utils/dotize";
import { GQLCOMMENT_STATUS } from "coral-server/graph/tenant/schema/__generated__/types";
import logger from "coral-server/logger";
import { EncodedCommentActionCounts } from "coral-server/models/action/comment";
import { PUBLISHED_STATUSES } from "coral-server/models/comment/constants";
import {
CommentStatusCounts,
createEmptyCommentStatusCounts,
@@ -226,3 +227,16 @@ export function calculateTotalCommentCount(
}
return count;
}
/**
* calculateTotalPublishedCommentCount will compute the total amount of
* published comments in a story by parsing the `CommentStatusCounts`.
*/
export function calculateTotalPublishedCommentCount(
commentCounts: CommentStatusCounts
) {
return PUBLISHED_STATUSES.reduce(
(total, status) => total + commentCounts[status],
0
);
}