Skip to content

Commit

Permalink
fix(topic-events): repeated invocations of Posts.addTopicEvents cause…
Browse files Browse the repository at this point in the history
…d dupes to be added to DOM
  • Loading branch information
julianlam committed Jan 27, 2021
1 parent 9559fad commit df2fdd5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions public/src/client/topic/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/topics/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit df2fdd5

Please sign in to comment.