mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
revamped configuration for moderation phases
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const {getScores, isToxic} = require('./perspective');
|
||||
const {ErrToxic} = require('./errors');
|
||||
const ActionsService = require('../../../services/actions');
|
||||
|
||||
// We don't add the hooks during _test_ as the perspective API is not available.
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
@@ -12,53 +11,36 @@ module.exports = {
|
||||
createComment: {
|
||||
async pre(_, {input}, _context, _info) {
|
||||
|
||||
let scores;
|
||||
|
||||
// Try getting scores.
|
||||
let scores;
|
||||
try {
|
||||
scores = await getScores(input.body);
|
||||
}
|
||||
catch(err) {
|
||||
} catch(err) {
|
||||
|
||||
// Warn and let mutation pass.
|
||||
console.trace(err);
|
||||
return;
|
||||
}
|
||||
|
||||
const commentIsToxic = isToxic(scores);
|
||||
|
||||
if (input.checkToxicity && commentIsToxic) {
|
||||
throw ErrToxic;
|
||||
}
|
||||
|
||||
// attach scores to metadata.
|
||||
// Attach scores to metadata.
|
||||
input.metadata = Object.assign({}, input.metadata, {
|
||||
perspective: scores,
|
||||
});
|
||||
|
||||
if (commentIsToxic) {
|
||||
if (isToxic(scores)) {
|
||||
if (input.checkToxicity) {
|
||||
throw ErrToxic;
|
||||
}
|
||||
|
||||
input.status = 'SYSTEM_WITHHELD';
|
||||
}
|
||||
},
|
||||
async post(_, _input, _context, _info, result) {
|
||||
const metadata = result.comment.metadata;
|
||||
if (metadata.perspective && isToxic(metadata.perspective)) {
|
||||
|
||||
// TODO: this is kind of fragile, we should refactor this to resolve
|
||||
// all these const's that we're using like 'COMMENTS', 'FLAG' to be
|
||||
// defined in a checkable schema.
|
||||
|
||||
// Add a flag to the comment.
|
||||
await ActionsService.create({
|
||||
item_id: result.comment.id,
|
||||
item_type: 'COMMENTS',
|
||||
input.actions = input.actions && input.actions.length >= 0 ? input.actions : [];
|
||||
input.actions.push({
|
||||
action_type: 'FLAG',
|
||||
user_id: null,
|
||||
group_id: 'Comment contains toxic language',
|
||||
metadata: {}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user