diff --git a/src/core/server/models/comment/revision.ts b/src/core/server/models/comment/revision.ts index 6a20d04e7..a28d3133c 100644 --- a/src/core/server/models/comment/revision.ts +++ b/src/core/server/models/comment/revision.ts @@ -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; } /** diff --git a/src/core/server/services/comments/pipeline/phases/toxic.ts b/src/core/server/services/comments/pipeline/phases/toxic.ts index afc02896f..afd924096 100644 --- a/src/core/server/services/comments/pipeline/phases/toxic.ts +++ b/src/core/server/services/comments/pipeline/phases/toxic.ts @@ -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 => { 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: { diff --git a/src/core/server/services/comments/pipeline/pipeline.ts b/src/core/server/services/comments/pipeline/pipeline.ts index 9e6e8d6df..c4e834428 100644 --- a/src/core/server/services/comments/pipeline/pipeline.ts +++ b/src/core/server/services/comments/pipeline/pipeline.ts @@ -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: [], };