Skip to content

Commit

Permalink
feat: banning a user will resolve their post flags
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Aug 22, 2020
1 parent 4f7cfd5 commit 354e6cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/flags.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/socket.io/user/ban.js
Expand Up @@ -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,
Expand Down

0 comments on commit 354e6cc

Please sign in to comment.