Skip to content

Commit

Permalink
adding one more helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
njouud committed Sep 3, 2024
1 parent a47eb5a commit 3f5ef12
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/topics/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,20 @@ module.exports = function (Topics) {
if (!postData.length) {
return;
}
postData.forEach((p, index) => {
function setEventTimes(p, nextPost, reverse, topicData) {
if (p && p.index === 0 && reverse) {
p.eventStart = topicData.lastposttime;
p.eventEnd = Date.now();
} else if (p && postData[index + 1]) {
p.eventStart = reverse ? postData[index + 1].timestamp : p.timestamp;
p.eventEnd = reverse ? p.timestamp : postData[index + 1].timestamp;
} else if (p && nextPost) {
p.eventStart = reverse ? nextPost.timestamp : p.timestamp;
p.eventEnd = reverse ? p.timestamp : nextPost.timestamp;
}
}
postData.forEach((p, index) => {
const nextPost = postData[index + 1];
setEventTimes(p, nextPost, reverse, topicData);
});
const lastPost = postData[postData.length - 1];
await handleLastPost(lastPost, set, reverse, topicData);
await handleLastPost(postData, set, reverse, topicData);
}

async function handleLastPost(lastPost, set, reverse, topicData) {
Expand Down

0 comments on commit 3f5ef12

Please sign in to comment.