mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 01:56:12 +01:00
feat: banning a user will resolve their post flags
This commit is contained in:
16
src/flags.js
16
src/flags.js
@@ -16,6 +16,7 @@ const posts = require('./posts');
|
|||||||
const privileges = require('./privileges');
|
const privileges = require('./privileges');
|
||||||
const plugins = require('./plugins');
|
const plugins = require('./plugins');
|
||||||
const utils = require('../public/src/utils');
|
const utils = require('../public/src/utils');
|
||||||
|
const batch = require('./batch');
|
||||||
|
|
||||||
const Flags = module.exports;
|
const Flags = module.exports;
|
||||||
|
|
||||||
@@ -571,6 +572,21 @@ Flags.resolveFlag = async function (type, id, uid) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Flags.resolveUserPostFlags = async function (uid, callerUid) {
|
||||||
|
await batch.processSortedSet('uid:' + uid + ':posts', async function (pids) {
|
||||||
|
let postData = await posts.getPostsFields(pids, ['pid', 'flagId']);
|
||||||
|
postData = postData.filter(p => p && p.flagId);
|
||||||
|
for (const postObj of postData) {
|
||||||
|
if (parseInt(postObj.flagId, 10)) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await Flags.update(postObj.flagId, callerUid, { state: 'resolved' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
batch: 500,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Flags.getHistory = async function (flagId) {
|
Flags.getHistory = async function (flagId) {
|
||||||
const uids = [];
|
const uids = [];
|
||||||
let history = await db.getSortedSetRevRangeWithScores('flag:' + flagId + ':history', 0, -1);
|
let history = await db.getSortedSetRevRangeWithScores('flag:' + flagId + ':history', 0, -1);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ module.exports = function (SocketUser) {
|
|||||||
await toggleBan(socket.uid, data.uids, async function (uid) {
|
await toggleBan(socket.uid, data.uids, async function (uid) {
|
||||||
await banUser(socket.uid, uid, data.until || 0, data.reason || '');
|
await banUser(socket.uid, uid, data.until || 0, data.reason || '');
|
||||||
await flags.resolveFlag('user', uid, socket.uid);
|
await flags.resolveFlag('user', uid, socket.uid);
|
||||||
|
await flags.resolveUserPostFlags(uid, socket.uid);
|
||||||
await events.log({
|
await events.log({
|
||||||
type: 'user-ban',
|
type: 'user-ban',
|
||||||
uid: socket.uid,
|
uid: socket.uid,
|
||||||
|
|||||||
Reference in New Issue
Block a user