mirror of
https://github.com/wassname/talk.git
synced 2026-08-16 11:29:31 +08:00
fix: added support for comment edit mod passthrough
This commit is contained in:
@@ -1,40 +1,59 @@
|
||||
const { getScores, isToxic } = require('./perspective');
|
||||
const { ErrToxic } = require('./errors');
|
||||
|
||||
function handlePositiveToxic(input) {
|
||||
input.status = 'SYSTEM_WITHHELD';
|
||||
input.actions =
|
||||
input.actions && input.actions.length >= 0 ? input.actions : [];
|
||||
input.actions.push({
|
||||
action_type: 'FLAG',
|
||||
user_id: null,
|
||||
group_id: 'TOXIC_COMMENT',
|
||||
metadata: {},
|
||||
});
|
||||
}
|
||||
|
||||
async function getScore(body) {
|
||||
// Try getting scores.
|
||||
let scores;
|
||||
try {
|
||||
scores = await getScores(body);
|
||||
} catch (err) {
|
||||
// Warn and let mutation pass.
|
||||
console.trace(err); // TODO: log/handle this differently?
|
||||
return;
|
||||
}
|
||||
|
||||
return scores;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RootMutation: {
|
||||
editComment: {
|
||||
pre: async (_, { edit: { body }, edit }) => {
|
||||
const scores = await getScore(body);
|
||||
if (isToxic(scores)) {
|
||||
handlePositiveToxic(edit);
|
||||
}
|
||||
},
|
||||
},
|
||||
createComment: {
|
||||
async pre(_, { input }, _context, _info) {
|
||||
// Try getting scores.
|
||||
let scores;
|
||||
try {
|
||||
scores = await getScores(input.body);
|
||||
} catch (err) {
|
||||
// Warn and let mutation pass.
|
||||
console.trace(err); // TODO: log/handle this differently?
|
||||
return;
|
||||
}
|
||||
|
||||
// Attach scores to metadata.
|
||||
input.metadata = Object.assign({}, input.metadata, {
|
||||
perspective: scores,
|
||||
});
|
||||
const scores = await getScore(input.body);
|
||||
|
||||
if (isToxic(scores)) {
|
||||
if (input.checkToxicity) {
|
||||
throw new ErrToxic();
|
||||
}
|
||||
|
||||
input.status = 'SYSTEM_WITHHELD';
|
||||
input.actions =
|
||||
input.actions && input.actions.length >= 0 ? input.actions : [];
|
||||
input.actions.push({
|
||||
action_type: 'FLAG',
|
||||
user_id: null,
|
||||
group_id: 'TOXIC_COMMENT',
|
||||
metadata: {},
|
||||
});
|
||||
// Mark the comment as positive toxic.
|
||||
handlePositiveToxic(input);
|
||||
}
|
||||
|
||||
// Attach scores to metadata.
|
||||
input.metadata = Object.assign({}, input.metadata, {
|
||||
perspective: scores,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user