feat(topic-events): work in progress topic events logic and client-side implementation

This commit is contained in:
Julian Lam
2021-01-03 12:44:20 -05:00
parent faf5960373
commit ab2e1ecb40
7 changed files with 149 additions and 1 deletions

View File

@@ -271,9 +271,38 @@ define('forum/topic/posts', [
posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
Posts.addBlockquoteEllipses(posts);
hidePostToolsForDeletedPosts(posts);
addTopicEvents();
addNecroPostMessage();
};
function addTopicEvents() {
if (config.topicPostSort !== 'newest_to_oldest' && config.topicPostSort !== 'oldest_to_newest') {
return;
}
// TODO: Handle oldest_to_newest
const postTimestamps = ajaxify.data.posts.map(post => post.timestamp);
ajaxify.data.events.forEach((event) => {
const beforeIdx = postTimestamps.findIndex(timestamp => timestamp > event.timestamp);
let postEl;
if (beforeIdx > -1) {
postEl = document.querySelector(`[component="post"][data-pid="${ajaxify.data.posts[beforeIdx].pid}"]`);
}
app.parseAndTranslate('partials/topic/event', event, function (html) {
html = html.get(0);
if (postEl) {
document.querySelector('[component="topic"]').insertBefore(html, postEl);
} else {
document.querySelector('[component="topic"]').append(html);
}
$(html).find('.timeago').timeago();
});
});
}
function addNecroPostMessage() {
var necroThreshold = ajaxify.data.necroThreshold * 24 * 60 * 60 * 1000;
if (!necroThreshold || (config.topicPostSort !== 'newest_to_oldest' && config.topicPostSort !== 'oldest_to_newest')) {