mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
[next] Flag Improvements (#2114)
* fix: applied fix for reaction mutation * fix: removed comment length flag * feat: added additionalDetails field to flags * feat: added other flag type
This commit is contained in:
@@ -226,7 +226,7 @@ export async function removeReaction(
|
||||
|
||||
export type CreateCommentDontAgree = Pick<
|
||||
CreateActionInput,
|
||||
"commentID" | "commentRevisionID"
|
||||
"commentID" | "commentRevisionID" | "additionalDetails"
|
||||
>;
|
||||
|
||||
export async function createDontAgree(
|
||||
@@ -240,6 +240,7 @@ export async function createDontAgree(
|
||||
actionType: ACTION_TYPE.DONT_AGREE,
|
||||
commentID: input.commentID,
|
||||
commentRevisionID: input.commentRevisionID,
|
||||
additionalDetails: input.additionalDetails,
|
||||
userID: author.id,
|
||||
});
|
||||
}
|
||||
@@ -262,7 +263,7 @@ export async function removeDontAgree(
|
||||
|
||||
export type CreateCommentFlag = Pick<
|
||||
CreateActionInput,
|
||||
"commentID" | "commentRevisionID"
|
||||
"commentID" | "commentRevisionID" | "additionalDetails"
|
||||
> & {
|
||||
reason: GQLCOMMENT_FLAG_REPORTED_REASON;
|
||||
};
|
||||
@@ -279,6 +280,7 @@ export async function createFlag(
|
||||
reason: input.reason,
|
||||
commentID: input.commentID,
|
||||
commentRevisionID: input.commentRevisionID,
|
||||
additionalDetails: input.additionalDetails,
|
||||
userID: author.id,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import striptags from "striptags";
|
||||
|
||||
import { isNil } from "lodash";
|
||||
import {
|
||||
GQLCOMMENT_FLAG_REASON,
|
||||
GQLCOMMENT_STATUS,
|
||||
} from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
import { ACTION_TYPE } from "talk-server/models/action/comment";
|
||||
import { ModerationSettings } from "talk-server/models/settings";
|
||||
import {
|
||||
IntermediateModerationPhase,
|
||||
@@ -16,22 +11,26 @@ const testCharCount = (
|
||||
settings: Partial<ModerationSettings>,
|
||||
length: number
|
||||
) => {
|
||||
// settings.charCount.enable && settings.charCount && length > settings.charCount;
|
||||
|
||||
if (settings.charCount && settings.charCount.enabled) {
|
||||
if (!isNil(settings.charCount.min)) {
|
||||
if (length < settings.charCount.min) {
|
||||
return true;
|
||||
throw new Error(
|
||||
`Body did not meet minimum length requirement of ${
|
||||
settings.charCount.min
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!isNil(settings.charCount.max)) {
|
||||
if (length > settings.charCount.max) {
|
||||
return true;
|
||||
throw new Error(
|
||||
`Body exceeded maximum length requirement of ${
|
||||
settings.charCount.max
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export const commentLength: IntermediateModerationPhase = ({
|
||||
@@ -42,22 +41,8 @@ export const commentLength: IntermediateModerationPhase = ({
|
||||
const length = comment.body ? striptags(comment.body).length : 0;
|
||||
|
||||
// Reject if the comment is too long or too short.
|
||||
if (
|
||||
testCharCount(tenant, length) ||
|
||||
(story.settings && testCharCount(story.settings, length))
|
||||
) {
|
||||
return {
|
||||
status: GQLCOMMENT_STATUS.REJECTED,
|
||||
actions: [
|
||||
{
|
||||
userID: null,
|
||||
actionType: ACTION_TYPE.FLAG,
|
||||
reason: GQLCOMMENT_FLAG_REASON.COMMENT_DETECTED_BODY_COUNT,
|
||||
metadata: {
|
||||
count: length,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
testCharCount(tenant, length);
|
||||
if (story.settings) {
|
||||
testCharCount(story.settings, length);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user