mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: merge consecutive share events
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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, rev
|
||||
return 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;
|
||||
|
||||
Reference in New Issue
Block a user