From aba420a3f3b774e949c2539c73f3dc0e1ae79a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 16 Aug 2022 18:06:16 -0400 Subject: [PATCH] feat: setting to show signatures only once in topics, closes #10071 --- install/data/defaults.json | 1 + public/language/en-GB/admin/settings/post.json | 1 + public/src/client/topic.js | 2 +- public/src/client/topic/posts.js | 17 +++++++++++++++++ src/controllers/topics.js | 1 + src/views/admin/settings/post.tpl | 6 ++++++ 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index 3f0e428fce..8623adf960 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -78,6 +78,7 @@ "reputation:disabled": 0, "downvote:disabled": 0, "disableSignatures": 0, + "signatures:hideDuplicates": 0, "upvotesPerDay": 20, "upvotesPerUserPerDay": 6, "downvotesPerDay": 10, diff --git a/public/language/en-GB/admin/settings/post.json b/public/language/en-GB/admin/settings/post.json index ab8245738c..57cc855319 100644 --- a/public/language/en-GB/admin/settings/post.json +++ b/public/language/en-GB/admin/settings/post.json @@ -51,6 +51,7 @@ "signature.disable": "Disable signatures", "signature.no-links": "Disable links in signatures", "signature.no-images": "Disable images in signatures", + "signature.hide-duplicates": "Hide duplicate signatures in topics", "signature.max-length": "Maximum Signature Length", "composer": "Composer Settings", "composer-help": "The following settings govern the functionality and/or appearance of the post composer shown\n\t\t\t\tto users when they create new topics, or reply to existing topics.", diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 0c111bcf7f..691e3a5543 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -40,7 +40,7 @@ define('forum/topic', [ app.enterRoom('topic_' + tid); posts.onTopicPageLoad(components.get('post')); - + posts.signaturesShown = {}; navigator.init('[component="post"]', ajaxify.data.postcount, Topic.toTop, Topic.toBottom, utils.debounce(Topic.navigatorCallback, 500)); postTools.init(tid); diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 9c7c7a245d..4e9e8501ae 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -14,6 +14,8 @@ define('forum/topic/posts', [ ], function (pagination, infinitescroll, postTools, images, navigator, components, translator, hooks, helpers) { const Posts = { }; + Posts.signaturesShown = {}; + Posts.onNewPost = function (data) { if ( !data || @@ -282,6 +284,7 @@ define('forum/topic/posts', [ Posts.onTopicPageLoad = function (posts) { handlePrivateUploads(posts); images.wrapImagesInLinks(posts); + hideDuplicateSignatures(posts); Posts.showBottomPostBar(); posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive'); Posts.addBlockquoteEllipses(posts); @@ -353,6 +356,20 @@ define('forum/topic/posts', [ }); } + function hideDuplicateSignatures(posts) { + if (ajaxify.data['signatures:hideDuplicates']) { + posts.each((index, el) => { + const signatureEl = $(el).find('[component="post/signature"]'); + const uid = signatureEl.attr('data-uid'); + if (Posts.signaturesShown[uid]) { + signatureEl.addClass('hidden'); + } else { + Posts.signaturesShown[uid] = true; + } + }); + } + } + function removeNecroPostMessages(removedPostEls) { removedPostEls.each((index, el) => { $(`[data-necro-post-index="${$(el).attr('data-index')}"]`).remove(); diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 807e546a00..a92570b8c8 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -88,6 +88,7 @@ topicsController.get = async function getTopic(req, res, next) { topicData['reputation:disabled'] = meta.config['reputation:disabled']; topicData['downvote:disabled'] = meta.config['downvote:disabled']; topicData['feeds:disableRSS'] = meta.config['feeds:disableRSS'] || 0; + topicData['signatures:hideDuplicates'] = meta.config['signatures:hideDuplicates']; topicData.bookmarkThreshold = meta.config.bookmarkThreshold; topicData.necroThreshold = meta.config.necroThreshold; topicData.postEditDuration = meta.config.postEditDuration; diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tpl index 6c018ec974..8e8d2e76bc 100644 --- a/src/views/admin/settings/post.tpl +++ b/src/views/admin/settings/post.tpl @@ -259,6 +259,12 @@ [[admin/settings/post:signature.no-images]] +
+ +