Node.js based forum software built for the modern web
feat: merge consecutive share events
Barış Soner Uşaklı9153f8cfaea2
diff --git a/install/package.json b/install/package.jsonindex 7ce6758f19..a72f022c1f 100644--- a/install/package.json+++ b/install/package.json@@ -108,7 +108,7 @@"nodebb-plugin-spam-be-gone": "2.3.1","nodebb-plugin-web-push": "0.7.2","nodebb-rewards-essentials": "1.0.1",- "nodebb-theme-harmony": "2.0.29",+ "nodebb-theme-harmony": "2.0.30","nodebb-theme-lavender": "7.1.17","nodebb-theme-peace": "2.2.39","nodebb-theme-persona": "14.0.15",diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.jsindex 38db844cdd..a83a9d86b5 100644--- a/public/src/client/topic/threadTools.js+++ b/public/src/client/topic/threadTools.js@@ -85,12 +85,24 @@ define('forum/topic/threadTools', [topicContainer.on('click', '[component="topic/event/delete"]', function () {const eventId = $(this).attr('data-topic-event-id');- const eventEl = $(this).parents('[component="topic/event"]');+ const eventEl = $(this).parents('[data-topic-event-id]');bootbox.confirm('[[topic:delete-event-confirm]]', (ok) => {if (ok) {api.del(`/topics/${tid}/events/${eventId}`, {}).then(function () {+ const itemsParent = eventEl.parents('[component="topic/event/items"]');eventEl.remove();+ if (itemsParent.length) {+ const childrenCount = itemsParent.children().length;+ const eventParent = itemsParent.parents('[component="topic/event"]');+ if (!childrenCount) {+ eventParent.remove();+ } else {+ eventParent+ .find('[data-bs-toggle]')+ .translateText(`[[topic:announcers-x, ${childrenCount}]]`);+ }+ }}).catch(alerts.error);}diff --git a/src/topics/index.js b/src/topics/index.jsindex 07600e6311..5717f26126 100644--- a/src/topics/index.js+++ b/src/topics/index.js@@ -198,6 +198,7 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, rev);p.eventStart = undefined;p.eventEnd = undefined;+ p.events = mergeConsecutiveShareEvents(p.events);});topicData.category = category;@@ -230,6 +231,23 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, revreturn result.topic;};+function mergeConsecutiveShareEvents(arr) {+ return arr.reduce((acc, curr) => {+ const last = acc[acc.length - 1];+ if (last && last.type === curr.type && last.type === 'share') {+ if (!last.items) {+ last.items = [{ ...last }];+ ['user', 'text', 'timestamp', 'timestampISO'].forEach(field => delete last[field]);+ }+ last.items.push(curr);+ } else {+ acc.push(curr);+ }+ return acc;+ }, []);+}++async function getDeleter(topicData) {if (!parseInt(topicData.deleterUid, 10)) {return null;