Skip to content

Commit

Permalink
refactor(topic-events): expose addTopicEvents method in topic posts lib
Browse files Browse the repository at this point in the history
+ allow it to accept an array of events, or fall back to ajaxify data otherwise
  • Loading branch information
julianlam committed Jan 27, 2021
1 parent cec3fc9 commit 9559fad
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions public/src/client/topic/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,24 @@ define('forum/topic/posts', [
posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
Posts.addBlockquoteEllipses(posts);
hidePostToolsForDeletedPosts(posts);
addTopicEvents();
Posts.addTopicEvents();
addNecroPostMessage();
};

function addTopicEvents() {
Posts.addTopicEvents = function (events) {
events = events || ajaxify.data.events;
if (!events || !Array.isArray(events)) {
return;
}

if (config.topicPostSort !== 'newest_to_oldest' && config.topicPostSort !== 'oldest_to_newest') {
return;
}

let postTimestamps = ajaxify.data.posts.map(post => post.timestamp);

const reverse = config.topicPostSort === 'newest_to_oldest';
const events = ajaxify.data.events.slice(0);
events = events.slice(0);
if (reverse) {
events.reverse();
postTimestamps = postTimestamps.slice(1); // OP is always at top, so exclude from calculations
Expand Down Expand Up @@ -314,7 +319,7 @@ define('forum/topic/posts', [
})).then(() => {
$('[component="topic/event"] .timeago').timeago();
});
}
};

function addNecroPostMessage() {
var necroThreshold = ajaxify.data.necroThreshold * 24 * 60 * 60 * 1000;
Expand Down

0 comments on commit 9559fad

Please sign in to comment.