mirror of
https://github.com/wassname/talk.git
synced 2026-08-13 12:40:11 +08:00
[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:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user