mirror of
https://github.com/wassname/talk.git
synced 2026-06-27 16:32:15 +08:00
feat: add additional log messages, added nudge to metadata (#2781)
Co-authored-by: Kim Gardner <kgardnr@gmail.com>
This commit is contained in:
@@ -1,12 +1,38 @@
|
||||
import { EncodedCommentActionCounts } from "coral-server/models/action/comment";
|
||||
|
||||
export interface RevisionMetadata {
|
||||
/**
|
||||
* akismet is true when it was determined to be spam.
|
||||
*/
|
||||
akismet?: boolean;
|
||||
|
||||
/**
|
||||
* linkCount is the number of links in a revision body that was detected.
|
||||
*/
|
||||
linkCount?: number;
|
||||
|
||||
/**
|
||||
* perspective stores the detected properties from checking with the
|
||||
* perspective model.
|
||||
*/
|
||||
perspective?: {
|
||||
/**
|
||||
* score is the percentage likelihood (in decimal form) that the comment
|
||||
* matches the selected model.
|
||||
*/
|
||||
score: number;
|
||||
|
||||
/**
|
||||
* model is the perspective model used to determine the above score.
|
||||
*/
|
||||
model: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* nudge when true indicates that the comment was written on the first try
|
||||
* without a warning.
|
||||
*/
|
||||
nudge?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
import { LanguageCode } from "coral-common/helpers";
|
||||
import { Omit } from "coral-common/types";
|
||||
import { ToxicCommentError } from "coral-server/errors";
|
||||
import logger from "coral-server/logger";
|
||||
import { ACTION_TYPE } from "coral-server/models/action/comment";
|
||||
import { hasFeatureFlag } from "coral-server/models/tenant";
|
||||
import {
|
||||
@@ -33,9 +32,12 @@ export const toxic: IntermediateModerationPhase = async ({
|
||||
nudge,
|
||||
log,
|
||||
htmlStripped,
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
comment: { body },
|
||||
}: Pick<
|
||||
ModerationPhaseContext,
|
||||
"tenant" | "nudge" | "log" | "htmlStripped"
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
"tenant" | "nudge" | "log" | "htmlStripped" | "comment"
|
||||
>): Promise<IntermediatePhaseResult | void> => {
|
||||
if (!htmlStripped) {
|
||||
return;
|
||||
@@ -91,7 +93,9 @@ export const toxic: IntermediateModerationPhase = async ({
|
||||
const timeout = ms("800ms");
|
||||
|
||||
try {
|
||||
logger.trace("checking comment toxicity");
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
log.info({ body }, "checking comment toxicity");
|
||||
// log.trace("checking comment toxicity");
|
||||
|
||||
// Pull the custom model out.
|
||||
const model = integration.model || TOXICITY_MODEL_DEFAULT;
|
||||
@@ -116,11 +120,13 @@ export const toxic: IntermediateModerationPhase = async ({
|
||||
|
||||
const isToxic = score > threshold;
|
||||
if (isToxic) {
|
||||
log.trace({ score, isToxic, threshold, model }, "comment was toxic");
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
log.info({ score, isToxic, threshold, model }, "comment was toxic");
|
||||
// log.trace({ score, isToxic, threshold, model }, "comment was toxic");
|
||||
|
||||
// Throw an error if we're nudging instead of recording.
|
||||
if (nudge) {
|
||||
// Only if the feature flag for disabling this behavior is not enabled.
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
if (
|
||||
!hasFeatureFlag(
|
||||
tenant,
|
||||
@@ -152,7 +158,9 @@ export const toxic: IntermediateModerationPhase = async ({
|
||||
};
|
||||
}
|
||||
|
||||
log.trace({ score, isToxic, threshold }, "comment was not toxic");
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
log.info({ score, isToxic, threshold }, "comment was not toxic");
|
||||
// log.trace({ score, isToxic, threshold }, "comment was not toxic");
|
||||
|
||||
return {
|
||||
metadata: {
|
||||
|
||||
@@ -81,7 +81,13 @@ export const compose = (
|
||||
status: GQLCOMMENT_STATUS.NONE,
|
||||
body: context.comment.body,
|
||||
actions: [],
|
||||
metadata: context.comment.metadata || {},
|
||||
metadata: {
|
||||
// Merge in the passed comment metadata.
|
||||
...(context.comment.metadata || {}),
|
||||
|
||||
// Add the nudge to the comment metadata.
|
||||
nudge: context.nudge,
|
||||
},
|
||||
tags: [],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user