mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #11531, fix teasers
1. with scheduled topics, pid is no longer reliable, lower pid can have higher timestamp(scheduled in the future) so use timestamp for sorting teasers 2. when restoring/deleting topics, update the teaser tid as the last step because it checks topicData.deleted
This commit is contained in:
@@ -131,7 +131,7 @@ module.exports = function (Categories) {
|
||||
categories.forEach((category) => {
|
||||
if (category) {
|
||||
category.posts = topics.filter(t => t.cid && (t.cid === category.cid || t.parentCids.includes(category.cid)))
|
||||
.sort((a, b) => b.pid - a.pid)
|
||||
.sort((a, b) => b.timestamp - a.timestamp)
|
||||
.slice(0, parseInt(category.numRecentReplies, 10));
|
||||
}
|
||||
});
|
||||
@@ -147,7 +147,7 @@ module.exports = function (Categories) {
|
||||
const posts = [];
|
||||
getPostsRecursive(category, posts);
|
||||
|
||||
posts.sort((a, b) => b.pid - a.pid);
|
||||
posts.sort((a, b) => b.timestamp - a.timestamp);
|
||||
if (posts.length) {
|
||||
category.posts = [posts[0]];
|
||||
}
|
||||
|
||||
@@ -11,44 +11,40 @@ const batch = require('../batch');
|
||||
|
||||
module.exports = function (Topics) {
|
||||
Topics.delete = async function (tid, uid) {
|
||||
await removeTopicPidsFromCid(tid);
|
||||
const cid = await Topics.getTopicField(tid, 'cid');
|
||||
await removeTopicPidsFromCid(tid, cid);
|
||||
await Topics.setTopicFields(tid, {
|
||||
deleted: 1,
|
||||
deleterUid: uid,
|
||||
deletedTimestamp: Date.now(),
|
||||
});
|
||||
await categories.updateRecentTidForCid(cid);
|
||||
};
|
||||
|
||||
async function removeTopicPidsFromCid(tid) {
|
||||
const [cid, pids] = await Promise.all([
|
||||
Topics.getTopicField(tid, 'cid'),
|
||||
Topics.getPids(tid),
|
||||
]);
|
||||
async function removeTopicPidsFromCid(tid, cid) {
|
||||
const pids = await Topics.getPids(tid);
|
||||
await db.sortedSetRemove(`cid:${cid}:pids`, pids);
|
||||
await categories.updateRecentTidForCid(cid);
|
||||
}
|
||||
|
||||
async function addTopicPidsToCid(tid) {
|
||||
const [cid, pids] = await Promise.all([
|
||||
Topics.getTopicField(tid, 'cid'),
|
||||
Topics.getPids(tid),
|
||||
]);
|
||||
async function addTopicPidsToCid(tid, cid) {
|
||||
const pids = await Topics.getPids(tid);
|
||||
let postData = await posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted']);
|
||||
postData = postData.filter(post => post && !post.deleted);
|
||||
const pidsToAdd = postData.map(post => post.pid);
|
||||
const scores = postData.map(post => post.timestamp);
|
||||
await db.sortedSetAdd(`cid:${cid}:pids`, scores, pidsToAdd);
|
||||
await categories.updateRecentTidForCid(cid);
|
||||
}
|
||||
|
||||
Topics.restore = async function (tid) {
|
||||
const cid = await Topics.getTopicField(tid, 'cid');
|
||||
await Promise.all([
|
||||
Topics.deleteTopicFields(tid, [
|
||||
'deleterUid', 'deletedTimestamp',
|
||||
]),
|
||||
addTopicPidsToCid(tid),
|
||||
addTopicPidsToCid(tid, cid),
|
||||
]);
|
||||
await Topics.setTopicField(tid, 'deleted', 0);
|
||||
await categories.updateRecentTidForCid(cid);
|
||||
};
|
||||
|
||||
Topics.purgePostsAndTopic = async function (tid, uid) {
|
||||
|
||||
Reference in New Issue
Block a user