fix: #6407, fix feeds

display latest posts instead of oldest in topic rss feed
fix missing await that was causing rss_tokens to not function
fix feed test
more tests for getTopicWithPosts
This commit is contained in:
Barış Soner Uşaklı
2020-11-18 14:25:39 -05:00
parent 8de48c3935
commit fa4177c3bc
4 changed files with 130 additions and 27 deletions

View File

@@ -189,18 +189,20 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, rev
};
async function getMainPostAndReplies(topic, set, uid, start, stop, reverse) {
let repliesStart = start;
let repliesStop = stop;
if (stop > 0) {
stop -= 1;
repliesStop -= 1;
if (start > 0) {
start -= 1;
repliesStart -= 1;
}
}
const pids = await posts.getPidsFromSet(set, start, stop, reverse);
const pids = await posts.getPidsFromSet(set, repliesStart, repliesStop, reverse);
if (!pids.length && !topic.mainPid) {
return [];
}
if (parseInt(topic.mainPid, 10) && start === 0) {
if (topic.mainPid && start === 0) {
pids.unshift(topic.mainPid);
}
const postData = await posts.getPostsByPids(pids, uid);
@@ -213,7 +215,7 @@ async function getMainPostAndReplies(topic, set, uid, start, stop, reverse) {
replies = postData.slice(1);
}
Topics.calculatePostIndices(replies, start);
Topics.calculatePostIndices(replies, repliesStart);
return await Topics.addPostData(postData, uid);
}