fix: #10090, remove left over necro posts messages

isekai-main
Barış Soner Uşaklı 3 years ago
parent c0dd8dcb1f
commit fdaf8274cf

@ -103,21 +103,21 @@ define('forum/infinitescroll', ['hooks', 'alerts'], function (hooks, alerts) {
}; };
scroll.removeExtra = function (els, direction, count) { scroll.removeExtra = function (els, direction, count) {
let removedEls = $();
if (els.length <= count) { if (els.length <= count) {
return; return removedEls;
} }
const removeCount = els.length - count; const removeCount = els.length - count;
if (direction > 0) { if (direction > 0) {
const height = $(document).height(); const height = $(document).height();
const scrollTop = $(window).scrollTop(); const scrollTop = $(window).scrollTop();
removedEls = els.slice(0, removeCount).remove();
els.slice(0, removeCount).remove();
$(window).scrollTop(scrollTop + ($(document).height() - height)); $(window).scrollTop(scrollTop + ($(document).height() - height));
} else { } else {
els.slice(els.length - removeCount).remove(); removedEls = els.slice(els.length - removeCount).remove();
} }
return removedEls;
}; };
return scroll; return scroll;

@ -230,7 +230,8 @@ define('forum/topic/posts', [
components.get('topic').append(html); components.get('topic').append(html);
} }
infinitescroll.removeExtra($('[component="post"]'), direction, Math.max(20, config.postsPerPage * 2)); const removedEls = infinitescroll.removeExtra($('[component="post"]'), direction, Math.max(20, config.postsPerPage * 2));
removeNecroPostMessages(removedEls);
hooks.fire('action:posts.loaded', { posts: data.posts }); hooks.fire('action:posts.loaded', { posts: data.posts });
@ -309,14 +310,14 @@ define('forum/topic/posts', [
}); });
}; };
function addNecroPostMessage(callback) { function addNecroPostMessage() {
const necroThreshold = ajaxify.data.necroThreshold * 24 * 60 * 60 * 1000; const necroThreshold = ajaxify.data.necroThreshold * 24 * 60 * 60 * 1000;
if (!necroThreshold || (config.topicPostSort !== 'newest_to_oldest' && config.topicPostSort !== 'oldest_to_newest')) { if (!necroThreshold || (config.topicPostSort !== 'newest_to_oldest' && config.topicPostSort !== 'oldest_to_newest')) {
return callback && callback(); return;
} }
const postEls = $('[component="post"]').toArray(); const postEls = $('[component="post"]').toArray();
Promise.all(postEls.map(function (post) { postEls.forEach(function (post) {
post = $(post); post = $(post);
const prev = post.prev('[component="post"]'); const prev = post.prev('[component="post"]');
if (post.is(':has(.necro-post)') || !prev.length) { if (post.is(':has(.necro-post)') || !prev.length) {
@ -327,7 +328,6 @@ define('forum/topic/posts', [
} }
const diff = post.attr('data-timestamp') - prev.attr('data-timestamp'); const diff = post.attr('data-timestamp') - prev.attr('data-timestamp');
return new Promise(function (resolve) {
if (Math.abs(diff) >= necroThreshold) { if (Math.abs(diff) >= necroThreshold) {
const suffixAgo = $.timeago.settings.strings.suffixAgo; const suffixAgo = $.timeago.settings.strings.suffixAgo;
const prefixAgo = $.timeago.settings.strings.prefixAgo; const prefixAgo = $.timeago.settings.strings.prefixAgo;
@ -346,17 +346,16 @@ define('forum/topic/posts', [
$.timeago.settings.strings.suffixFromNow = suffixFromNow; $.timeago.settings.strings.suffixFromNow = suffixFromNow;
$.timeago.settings.strings.prefixFromNow = prefixFromNow; $.timeago.settings.strings.prefixFromNow = prefixFromNow;
app.parseAndTranslate('partials/topic/necro-post', { text: translationText }, function (html) { app.parseAndTranslate('partials/topic/necro-post', { text: translationText }, function (html) {
html.attr('data-necro-post-index', prev.attr('data-index'));
html.insertBefore(post); html.insertBefore(post);
resolve();
}); });
} else {
resolve();
} }
}); });
})).then(function () {
if (typeof callback === 'function') {
callback();
} }
function removeNecroPostMessages(removedPostEls) {
removedPostEls.each((index, el) => {
$(`[data-necro-post-index="${$(el).attr('data-index')}"]`).remove();
}); });
} }

Loading…
Cancel
Save