Skip to content

Commit aa6ff2c

Browse files
author
Farzad Hayatbakhsh
committed
Deep copy events to avoid modifying original event log data.
1 parent be7ddd3 commit aa6ff2c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/ROOT/partials/plugin-apis/comments-apis.adoc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,19 @@ console.log(comments.getEventLog(
144144
145145
const eventLog = comments.getEventLog();
146146
const events = eventLog.events;
147+
147148
// Ensure that the mentioned users are valid users in the database
148-
events.forEach((event) => {
149+
const validatedEvents = JSON.parse(JSON.stringify(events));
150+
validatedEvents.forEach((event) => {
151+
// Filter out invalid users - change this to your own validation logic
149152
event.mentionedUids = event.mentionedUids ? event.mentionedUids.filter((uid) => users[uid]) : undefined;
150153
});
151-
const mentionedUsers = events.flatMap(({ mentionedUids }) => mentionedUids || []);
154+
155+
const mentionedUsers = validatedEvents.flatMap(({ mentionedUids }) => mentionedUids || []);
152156
console.log(mentionedUsers);
153157
154158
let whoMentionedWho = {};
155-
events.forEach((event) => {
159+
validatedEvents.forEach((event) => {
156160
if ((event.type === "create" || event.type === "reply") && event.mentionedUids !== undefined) {
157161
console.log(event);
158162
if (whoMentionedWho[event.conversationAuthor.author] === undefined) {

0 commit comments

Comments
 (0)