From df2fdd56ba0fedbee0748de3c887879a0a437beb Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 12 Jan 2021 11:42:06 -0500 Subject: [PATCH] fix(topic-events): repeated invocations of Posts.addTopicEvents caused dupes to be added to DOM --- public/src/client/topic/posts.js | 4 ++++ src/topics/events.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index b0356e9e24..451226f097 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -285,6 +285,10 @@ define('forum/topic/posts', [ return; } + // Filter out events already in DOM + const eventIdsInDOM = Array.from(document.querySelectorAll('[component="topic/event"]')).map(el => parseInt(el.getAttribute('data-topic-event-id'), 10)); + events = events.filter(event => !eventIdsInDOM.includes(event.id)); + let postTimestamps = ajaxify.data.posts.map(post => post.timestamp); const reverse = config.topicPostSort === 'newest_to_oldest'; diff --git a/src/topics/events.js b/src/topics/events.js index 7c85c362e0..dc5d80906f 100644 --- a/src/topics/events.js +++ b/src/topics/events.js @@ -126,6 +126,6 @@ Events.log = async (tid, payload) => { events: [payload], }); - ({ events } = plugins.hooks.fire('filter:topic.events.log', { events })); + ({ events } = await plugins.hooks.fire('filter:topic.events.log', { events })); return events; };