Skip to content

Node.js based forum software built for the modern web

fix: #11531, fix teasers

Barış Soner Uşaklıc23689d30521
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index 58f46313b3..7b04974659 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -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]];
}
diff --git a/src/topics/delete.js b/src/topics/delete.js
index 2e088f35c5..75472ffc69 100644
--- a/src/topics/delete.js
+++ b/src/topics/delete.js
@@ -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) {