mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
feat: do not show the replies container in a post's footer if the only reply present is the next post
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
define('forum/topic/replies', ['forum/topic/posts', 'hooks', 'alerts'], function (posts, hooks, alerts) {
|
define('forum/topic/replies', ['forum/topic/posts', 'hooks', 'alerts', 'components'], function (posts, hooks, alerts, components) {
|
||||||
const Replies = {};
|
const Replies = {};
|
||||||
|
|
||||||
Replies.init = function (button) {
|
Replies.init = function (button) {
|
||||||
@@ -85,14 +85,22 @@ define('forum/topic/replies', ['forum/topic/posts', 'hooks', 'alerts'], function
|
|||||||
};
|
};
|
||||||
|
|
||||||
function incrementCount(post, inc) {
|
function incrementCount(post, inc) {
|
||||||
|
const postEl = document.querySelector(`[component="post"][data-pid="${post.toPid}"]`);
|
||||||
|
if (!postEl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const replyCount = $('[component="post"][data-pid="' + post.toPid + '"]').find('[component="post/reply-count"]').first();
|
const replyCount = $('[component="post"][data-pid="' + post.toPid + '"]').find('[component="post/reply-count"]').first();
|
||||||
const countEl = replyCount.find('[component="post/reply-count/text"]');
|
const countEl = replyCount.find('[component="post/reply-count/text"]');
|
||||||
const avatars = replyCount.find('[component="post/reply-count/avatars"]');
|
const avatars = replyCount.find('[component="post/reply-count/avatars"]');
|
||||||
const count = Math.max(0, (parseInt(countEl.attr('data-replies'), 10) || 0) + inc);
|
const count = Math.max(0, (parseInt(countEl.attr('data-replies'), 10) || 0) + inc);
|
||||||
const timestamp = replyCount.find('.timeago').attr('title', post.timestampISO);
|
const timestamp = replyCount.find('.timeago').attr('title', post.timestampISO);
|
||||||
|
|
||||||
|
const index = postEl.getAttribute('data-index');
|
||||||
|
const hasSingleImmediateReply = count === 1 && Math.abs(post.index - index) === 1;
|
||||||
|
|
||||||
countEl.attr('data-replies', count);
|
countEl.attr('data-replies', count);
|
||||||
replyCount.toggleClass('hidden', count <= 0);
|
replyCount.toggleClass('hidden', count <= 0 || hasSingleImmediateReply);
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
countEl.translateText('[[topic:replies_to_this_post, ' + count + ']]');
|
countEl.translateText('[[topic:replies_to_this_post, ' + count + ']]');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,8 +27,10 @@ module.exports = function (utils, Benchpress, relative_path) {
|
|||||||
increment,
|
increment,
|
||||||
generateRepliedTo,
|
generateRepliedTo,
|
||||||
generateWrote,
|
generateWrote,
|
||||||
register,
|
|
||||||
isoTimeToLocaleString,
|
isoTimeToLocaleString,
|
||||||
|
shouldHideReplyContainer,
|
||||||
|
|
||||||
|
register,
|
||||||
__escape: identity,
|
__escape: identity,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -342,6 +344,14 @@ module.exports = function (utils, Benchpress, relative_path) {
|
|||||||
return new Date(isoTime).toLocaleString().replace(/,/g, ',');
|
return new Date(isoTime).toLocaleString().replace(/,/g, ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldHideReplyContainer(post) {
|
||||||
|
if (post.replies.count <= 0 || post.replies.hasSingleImmediateReply) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function register() {
|
function register() {
|
||||||
Object.keys(helpers).forEach(function (helperName) {
|
Object.keys(helpers).forEach(function (helperName) {
|
||||||
Benchpress.registerHelper(helperName, helpers[helperName]);
|
Benchpress.registerHelper(helperName, helpers[helperName]);
|
||||||
|
|||||||
@@ -319,6 +319,9 @@ module.exports = function (Topics) {
|
|||||||
const arrayOfReplyPids = await db.getSortedSetsMembers(keys);
|
const arrayOfReplyPids = await db.getSortedSetsMembers(keys);
|
||||||
|
|
||||||
const uniquePids = _.uniq(_.flatten(arrayOfReplyPids));
|
const uniquePids = _.uniq(_.flatten(arrayOfReplyPids));
|
||||||
|
const someTid = await posts.getPostField(pids[0], 'tid'); // the particular tid doesn't matter; used in getPostIndices but does not affect output
|
||||||
|
const pidIndices = await posts.getPostIndices(pids.map(pid => ({ pid, tid: someTid })));
|
||||||
|
const replyIndices = await posts.getPostIndices(uniquePids.map(pid => ({ pid, tid: someTid })));
|
||||||
|
|
||||||
let replyData = await posts.getPostsFields(uniquePids, ['pid', 'uid', 'timestamp']);
|
let replyData = await posts.getPostsFields(uniquePids, ['pid', 'uid', 'timestamp']);
|
||||||
const result = await plugins.hooks.fire('filter:topics.getPostReplies', {
|
const result = await plugins.hooks.fire('filter:topics.getPostReplies', {
|
||||||
@@ -335,12 +338,15 @@ module.exports = function (Topics) {
|
|||||||
|
|
||||||
const uidMap = _.zipObject(uniqueUids, userData);
|
const uidMap = _.zipObject(uniqueUids, userData);
|
||||||
const pidMap = _.zipObject(replyData.map(r => r.pid), replyData);
|
const pidMap = _.zipObject(replyData.map(r => r.pid), replyData);
|
||||||
|
const indicesMap = _.zipObject(replyData.map(r => r.pid), replyIndices);
|
||||||
|
|
||||||
const returnData = arrayOfReplyPids.map((replyPids) => {
|
const returnData = arrayOfReplyPids.map((replyPids, idx) => {
|
||||||
replyPids = replyPids.filter(pid => pidMap[pid]);
|
replyPids = replyPids.filter(pid => pidMap[pid]);
|
||||||
|
const currentIndex = pidIndices[idx];
|
||||||
const uidsUsed = {};
|
const uidsUsed = {};
|
||||||
const currentData = {
|
const currentData = {
|
||||||
hasMore: false,
|
hasMore: false,
|
||||||
|
hasSingleImmediateReply: replyPids.length === 1 && Math.abs(currentIndex - indicesMap[replyPids[0]]) === 1,
|
||||||
users: [],
|
users: [],
|
||||||
text: replyPids.length > 1 ? `[[topic:replies_to_this_post, ${replyPids.length}]]` : '[[topic:one_reply_to_this_post]]',
|
text: replyPids.length > 1 ? `[[topic:replies_to_this_post, ${replyPids.length}]]` : '[[topic:one_reply_to_this_post]]',
|
||||||
count: replyPids.length,
|
count: replyPids.length,
|
||||||
|
|||||||
Reference in New Issue
Block a user