mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-20 23:40:38 +01:00
* feat: post auto flagging on downvotes * fix: just get one admin
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
const meta = require('../meta');
|
||||
const db = require('../database');
|
||||
const flags = require('../flags');
|
||||
const user = require('../user');
|
||||
const topics = require('../topics');
|
||||
const plugins = require('../plugins');
|
||||
const privileges = require('../privileges');
|
||||
const translator = require('../translator');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
const votesInProgress = {};
|
||||
@@ -243,6 +245,13 @@ module.exports = function (Posts) {
|
||||
if (!postData || !postData.pid || !postData.tid) {
|
||||
return;
|
||||
}
|
||||
const threshold = meta.config['flags:autoFlagOnDownvoteThreshold'];
|
||||
if (threshold && postData.votes <= (-threshold)) {
|
||||
const adminUid = await user.getFirstAdminUid();
|
||||
const reportMsg = await translator.translate(`[[flags:auto-flagged, ${-postData.votes}]]`);
|
||||
const flagObj = await flags.create('post', postData.pid, adminUid, reportMsg, null, true);
|
||||
await flags.notify(flagObj, adminUid, true);
|
||||
}
|
||||
await Promise.all([
|
||||
updateTopicVoteCount(postData),
|
||||
db.sortedSetAdd('posts:votes', postData.votes, postData.pid),
|
||||
|
||||
Reference in New Issue
Block a user