mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
fix: #10090, remove left over necro posts messages
This commit is contained in:
@@ -103,21 +103,21 @@ define('forum/infinitescroll', ['hooks', 'alerts'], function (hooks, alerts) {
|
||||
};
|
||||
|
||||
scroll.removeExtra = function (els, direction, count) {
|
||||
let removedEls = $();
|
||||
if (els.length <= count) {
|
||||
return;
|
||||
return removedEls;
|
||||
}
|
||||
|
||||
const removeCount = els.length - count;
|
||||
if (direction > 0) {
|
||||
const height = $(document).height();
|
||||
const scrollTop = $(window).scrollTop();
|
||||
|
||||
els.slice(0, removeCount).remove();
|
||||
|
||||
removedEls = els.slice(0, removeCount).remove();
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
} else {
|
||||
els.slice(els.length - removeCount).remove();
|
||||
removedEls = els.slice(els.length - removeCount).remove();
|
||||
}
|
||||
return removedEls;
|
||||
};
|
||||
|
||||
return scroll;
|
||||
|
||||
@@ -230,7 +230,8 @@ define('forum/topic/posts', [
|
||||
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 });
|
||||
|
||||
@@ -309,14 +310,14 @@ define('forum/topic/posts', [
|
||||
});
|
||||
};
|
||||
|
||||
function addNecroPostMessage(callback) {
|
||||
function addNecroPostMessage() {
|
||||
const necroThreshold = ajaxify.data.necroThreshold * 24 * 60 * 60 * 1000;
|
||||
if (!necroThreshold || (config.topicPostSort !== 'newest_to_oldest' && config.topicPostSort !== 'oldest_to_newest')) {
|
||||
return callback && callback();
|
||||
return;
|
||||
}
|
||||
|
||||
const postEls = $('[component="post"]').toArray();
|
||||
Promise.all(postEls.map(function (post) {
|
||||
postEls.forEach(function (post) {
|
||||
post = $(post);
|
||||
const prev = post.prev('[component="post"]');
|
||||
if (post.is(':has(.necro-post)') || !prev.length) {
|
||||
@@ -327,39 +328,37 @@ define('forum/topic/posts', [
|
||||
}
|
||||
|
||||
const diff = post.attr('data-timestamp') - prev.attr('data-timestamp');
|
||||
return new Promise(function (resolve) {
|
||||
if (Math.abs(diff) >= necroThreshold) {
|
||||
const suffixAgo = $.timeago.settings.strings.suffixAgo;
|
||||
const prefixAgo = $.timeago.settings.strings.prefixAgo;
|
||||
const suffixFromNow = $.timeago.settings.strings.suffixFromNow;
|
||||
const prefixFromNow = $.timeago.settings.strings.prefixFromNow;
|
||||
if (Math.abs(diff) >= necroThreshold) {
|
||||
const suffixAgo = $.timeago.settings.strings.suffixAgo;
|
||||
const prefixAgo = $.timeago.settings.strings.prefixAgo;
|
||||
const suffixFromNow = $.timeago.settings.strings.suffixFromNow;
|
||||
const prefixFromNow = $.timeago.settings.strings.prefixFromNow;
|
||||
|
||||
$.timeago.settings.strings.suffixAgo = '';
|
||||
$.timeago.settings.strings.prefixAgo = '';
|
||||
$.timeago.settings.strings.suffixFromNow = '';
|
||||
$.timeago.settings.strings.prefixFromNow = '';
|
||||
$.timeago.settings.strings.suffixAgo = '';
|
||||
$.timeago.settings.strings.prefixAgo = '';
|
||||
$.timeago.settings.strings.suffixFromNow = '';
|
||||
$.timeago.settings.strings.prefixFromNow = '';
|
||||
|
||||
const translationText = (diff > 0 ? '[[topic:timeago_later,' : '[[topic:timeago_earlier,') + $.timeago.inWords(diff) + ']]';
|
||||
const translationText = (diff > 0 ? '[[topic:timeago_later,' : '[[topic:timeago_earlier,') + $.timeago.inWords(diff) + ']]';
|
||||
|
||||
$.timeago.settings.strings.suffixAgo = suffixAgo;
|
||||
$.timeago.settings.strings.prefixAgo = prefixAgo;
|
||||
$.timeago.settings.strings.suffixFromNow = suffixFromNow;
|
||||
$.timeago.settings.strings.prefixFromNow = prefixFromNow;
|
||||
app.parseAndTranslate('partials/topic/necro-post', { text: translationText }, function (html) {
|
||||
html.insertBefore(post);
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
})).then(function () {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
$.timeago.settings.strings.suffixAgo = suffixAgo;
|
||||
$.timeago.settings.strings.prefixAgo = prefixAgo;
|
||||
$.timeago.settings.strings.suffixFromNow = suffixFromNow;
|
||||
$.timeago.settings.strings.prefixFromNow = prefixFromNow;
|
||||
app.parseAndTranslate('partials/topic/necro-post', { text: translationText }, function (html) {
|
||||
html.attr('data-necro-post-index', prev.attr('data-index'));
|
||||
html.insertBefore(post);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeNecroPostMessages(removedPostEls) {
|
||||
removedPostEls.each((index, el) => {
|
||||
$(`[data-necro-post-index="${$(el).attr('data-index')}"]`).remove();
|
||||
});
|
||||
}
|
||||
|
||||
function handlePrivateUploads(posts) {
|
||||
if (app.user.uid || !ajaxify.data.privateUploads) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user