mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-23 19:21:16 +02:00
fix: #12485, resolve flags on a topics posts on topic delete
This commit is contained in:
@@ -236,7 +236,7 @@ module.exports = function (Posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function resolveFlags(postData, uid) {
|
async function resolveFlags(postData, uid) {
|
||||||
const flaggedPosts = postData.filter(p => parseInt(p.flagId, 10));
|
const flaggedPosts = postData.filter(p => p && parseInt(p.flagId, 10));
|
||||||
await Promise.all(flaggedPosts.map(p => flags.update(p.flagId, uid, { state: 'resolved' })));
|
await Promise.all(flaggedPosts.map(p => flags.update(p.flagId, uid, { state: 'resolved' })));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,25 +5,38 @@ const db = require('../database');
|
|||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const posts = require('../posts');
|
const posts = require('../posts');
|
||||||
const categories = require('../categories');
|
const categories = require('../categories');
|
||||||
|
const flags = require('../flags');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const batch = require('../batch');
|
const batch = require('../batch');
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
Topics.delete = async function (tid, uid) {
|
Topics.delete = async function (tid, uid) {
|
||||||
const cid = await Topics.getTopicField(tid, 'cid');
|
const [cid, pids] = await Promise.all([
|
||||||
await removeTopicPidsFromCid(tid, cid);
|
Topics.getTopicField(tid, 'cid'),
|
||||||
await Topics.setTopicFields(tid, {
|
Topics.getPids(tid),
|
||||||
deleted: 1,
|
]);
|
||||||
deleterUid: uid,
|
await Promise.all([
|
||||||
deletedTimestamp: Date.now(),
|
db.sortedSetRemove(`cid:${cid}:pids`, pids),
|
||||||
});
|
resolveTopicPostFlags(pids, uid),
|
||||||
|
Topics.setTopicFields(tid, {
|
||||||
|
deleted: 1,
|
||||||
|
deleterUid: uid,
|
||||||
|
deletedTimestamp: Date.now(),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
await categories.updateRecentTidForCid(cid);
|
await categories.updateRecentTidForCid(cid);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function removeTopicPidsFromCid(tid, cid) {
|
async function resolveTopicPostFlags(pids, uid) {
|
||||||
const pids = await Topics.getPids(tid);
|
await batch.processArray(pids, async (pids) => {
|
||||||
await db.sortedSetRemove(`cid:${cid}:pids`, pids);
|
const postData = await posts.getPostsFields(pids, ['pid', 'flagId']);
|
||||||
|
const flaggedPosts = postData.filter(p => p && parseInt(p.flagId, 10));
|
||||||
|
await Promise.all(flaggedPosts.map(p => flags.update(p.flagId, uid, { state: 'resolved' })));
|
||||||
|
}, {
|
||||||
|
batch: 500,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addTopicPidsToCid(tid, cid) {
|
async function addTopicPidsToCid(tid, cid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user