mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 10:37:45 +01:00
fix: consider crossposts when building teasers, fixes #13891
This commit is contained in:
@@ -96,10 +96,14 @@ module.exports = function (Categories) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function getTopics(tids, uid) {
|
async function getTopics(tids, uid) {
|
||||||
const topicData = await topics.getTopicsFields(
|
const [topicData, crossposts] = await Promise.all([
|
||||||
tids,
|
topics.getTopicsFields(
|
||||||
['tid', 'mainPid', 'slug', 'title', 'teaserPid', 'cid', 'postcount']
|
tids,
|
||||||
);
|
['tid', 'mainPid', 'slug', 'title', 'teaserPid', 'cid', 'postcount']
|
||||||
|
),
|
||||||
|
Promise.all(tids.map(async tid => topics.crossposts.get(tid))),
|
||||||
|
]);
|
||||||
|
|
||||||
topicData.forEach((topic) => {
|
topicData.forEach((topic) => {
|
||||||
if (topic) {
|
if (topic) {
|
||||||
topic.teaserPid = topic.teaserPid || topic.mainPid;
|
topic.teaserPid = topic.teaserPid || topic.mainPid;
|
||||||
@@ -124,6 +128,7 @@ module.exports = function (Categories) {
|
|||||||
slug: topicData[index].slug,
|
slug: topicData[index].slug,
|
||||||
title: topicData[index].title,
|
title: topicData[index].title,
|
||||||
};
|
};
|
||||||
|
teaser.crossposts = crossposts[index];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return teasers.filter(Boolean);
|
return teasers.filter(Boolean);
|
||||||
@@ -132,10 +137,12 @@ module.exports = function (Categories) {
|
|||||||
function assignTopicsToCategories(categories, topics) {
|
function assignTopicsToCategories(categories, topics) {
|
||||||
categories.forEach((category) => {
|
categories.forEach((category) => {
|
||||||
if (category) {
|
if (category) {
|
||||||
category.posts = topics.filter(
|
category.posts = topics.filter(t =>
|
||||||
t => t.cid &&
|
t.cid &&
|
||||||
(t.cid === category.cid || (t.parentCids && t.parentCids.includes(category.cid)))
|
(t.cid === category.cid ||
|
||||||
)
|
(t.parentCids && t.parentCids.includes(category.cid)) ||
|
||||||
|
(t.crossposts.some(({ cid }) => parseInt(cid, 10) === category.cid))
|
||||||
|
))
|
||||||
.sort((a, b) => b.timestamp - a.timestamp)
|
.sort((a, b) => b.timestamp - a.timestamp)
|
||||||
.slice(0, parseInt(category.numRecentReplies, 10));
|
.slice(0, parseInt(category.numRecentReplies, 10));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user