mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
fix: #9954, get next post timestamp
fixes topic events being inserted in after first page but at the wrong spot
This commit is contained in:
@@ -212,7 +212,7 @@
|
|||||||
|
|
||||||
function renderTopicEvents(index) {
|
function renderTopicEvents(index) {
|
||||||
const start = this.posts[index].timestamp;
|
const start = this.posts[index].timestamp;
|
||||||
const end = this.posts[index + 1] ? this.posts[index + 1].timestamp : Date.now();
|
const end = this.posts[index].nextPostTimestamp;
|
||||||
const events = this.events.filter(event => event.timestamp >= start && event.timestamp < end);
|
const events = this.events.filter(event => event.timestamp >= start && event.timestamp < end);
|
||||||
if (!events.length) {
|
if (!events.length) {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@@ -240,9 +240,26 @@ async function getMainPostAndReplies(topic, set, uid, start, stop, reverse) {
|
|||||||
|
|
||||||
Topics.calculatePostIndices(replies, repliesStart);
|
Topics.calculatePostIndices(replies, repliesStart);
|
||||||
|
|
||||||
|
await Topics.addNextPostTimestamp(postData, set, reverse);
|
||||||
return await Topics.addPostData(postData, uid);
|
return await Topics.addPostData(postData, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Topics.addNextPostTimestamp = async function (postData, set, reverse) {
|
||||||
|
if (!postData.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
postData.forEach((p, index) => {
|
||||||
|
if (p && postData[index + 1]) {
|
||||||
|
p.nextPostTimestamp = postData[index + 1].timestamp;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const lastPost = postData[postData.length - 1];
|
||||||
|
if (lastPost && lastPost.index) {
|
||||||
|
const data = await db[reverse ? 'getSortedSetRevRangeWithScores' : 'getSortedSetRangeWithScores'](set, lastPost.index, lastPost.index);
|
||||||
|
lastPost.nextPostTimestamp = data.length ? data[0].score : Date.now();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async function getDeleter(topicData) {
|
async function getDeleter(topicData) {
|
||||||
if (!parseInt(topicData.deleterUid, 10)) {
|
if (!parseInt(topicData.deleterUid, 10)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ module.exports = function (Topics) {
|
|||||||
const postData = await posts.getPostsFromSet(set, start, stop, uid, reverse);
|
const postData = await posts.getPostsFromSet(set, start, stop, uid, reverse);
|
||||||
Topics.calculatePostIndices(postData, start);
|
Topics.calculatePostIndices(postData, start);
|
||||||
|
|
||||||
|
await Topics.addNextPostTimestamp(postData, set, reverse);
|
||||||
return await Topics.addPostData(postData, uid);
|
return await Topics.addPostData(postData, uid);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user