mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
fix: #9370, show correct teaser index if sorting is newest to oldest
This commit is contained in:
@@ -43,12 +43,15 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let postData = await posts.getPostsFields(teaserPids, ['pid', 'uid', 'timestamp', 'tid', 'content']);
|
const [allPostData, callerSettings] = await Promise.all([
|
||||||
postData = postData.filter(post => post && post.pid);
|
posts.getPostsFields(teaserPids, ['pid', 'uid', 'timestamp', 'tid', 'content']),
|
||||||
|
user.getSettings(uid),
|
||||||
|
]);
|
||||||
|
let postData = allPostData.filter(post => post && post.pid);
|
||||||
postData = await handleBlocks(uid, postData);
|
postData = await handleBlocks(uid, postData);
|
||||||
postData = postData.filter(Boolean);
|
postData = postData.filter(Boolean);
|
||||||
const uids = _.uniq(postData.map(post => post.uid));
|
const uids = _.uniq(postData.map(post => post.uid));
|
||||||
|
const sortNewToOld = callerSettings.topicPostSort === 'newest_to_oldest';
|
||||||
const usersData = await user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture']);
|
const usersData = await user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture']);
|
||||||
|
|
||||||
const users = {};
|
const users = {};
|
||||||
@@ -75,7 +78,7 @@ module.exports = function (Topics) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (tidToPost[topic.tid]) {
|
if (tidToPost[topic.tid]) {
|
||||||
tidToPost[topic.tid].index = meta.config.teaserPost === 'first' ? 1 : counts[index];
|
tidToPost[topic.tid].index = calcTeaserIndex(teaserPost, counts[index], sortNewToOld);
|
||||||
if (tidToPost[topic.tid].content) {
|
if (tidToPost[topic.tid].content) {
|
||||||
tidToPost[topic.tid].content = utils.stripHTMLTags(replaceImgWithAltText(tidToPost[topic.tid].content), tags);
|
tidToPost[topic.tid].content = utils.stripHTMLTags(replaceImgWithAltText(tidToPost[topic.tid].content), tags);
|
||||||
}
|
}
|
||||||
@@ -87,6 +90,17 @@ module.exports = function (Topics) {
|
|||||||
return result.teasers;
|
return result.teasers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function calcTeaserIndex(teaserPost, postCountInTopic, sortNewToOld) {
|
||||||
|
if (teaserPost === 'first') {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortNewToOld) {
|
||||||
|
return Math.min(2, postCountInTopic);
|
||||||
|
}
|
||||||
|
return postCountInTopic;
|
||||||
|
}
|
||||||
|
|
||||||
function replaceImgWithAltText(str) {
|
function replaceImgWithAltText(str) {
|
||||||
return String(str).replace(/<img .*?alt="(.*?)"[^>]*>/gi, '$1');
|
return String(str).replace(/<img .*?alt="(.*?)"[^>]*>/gi, '$1');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user