feat: banning a user will resolve their post flags

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 4f7cfd5372
commit 354e6ccc66

@ -16,6 +16,7 @@ const posts = require('./posts');
const privileges = require('./privileges');
const plugins = require('./plugins');
const utils = require('../public/src/utils');
const batch = require('./batch');
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) {
const uids = [];
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 banUser(socket.uid, uid, data.until || 0, data.reason || '');
await flags.resolveFlag('user', uid, socket.uid);
await flags.resolveUserPostFlags(uid, socket.uid);
await events.log({
type: 'user-ban',
uid: socket.uid,

Loading…
Cancel
Save