Skip to content

Commit d9accbe

Browse files
Farzad HayatMitchC1999kemister85
authored
DOC-2587: Improve Comments documentation for mentionedUids validation (#3524)
* Admonition about known limitation of mentionedUids user validation * Validate mentionedUids in each of the events * Deep copy events to avoid modifying original event log data. * Update modules/ROOT/partials/plugin-apis/comments-apis.adoc Co-authored-by: Mitchell Crompton <[email protected]> * Update modules/ROOT/partials/plugin-apis/comments-apis.adoc Co-authored-by: Karl Kemister-Sheppard <[email protected]> * Improve the sample user database --------- Co-authored-by: Mitchell Crompton <[email protected]> Co-authored-by: Karl Kemister-Sheppard <[email protected]>
1 parent be71cde commit d9accbe

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,37 @@ When the xref:mentions.adoc[Mentions] plugin is enabled, each of the above event
118118

119119
It is recommended to use this API to retrieve which users have been mentioned in comments.
120120

121+
[NOTE]
122+
====
123+
The `mentionedUids` array captures strings following the `@` symbol without verifying if they correspond to valid user IDs. It is the integrator's responsibility to validate these strings against the database to ensure they represent valid users.
124+
125+
For guidance on retrieving and verifying the `mentionedUids` array, refer to the xref:#example-using-geteventlog[getEventLog example].
126+
127+
====
128+
129+
[[example-using-geteventlog]]
121130
==== Example: using `+getEventLog()+`
122131

123132
[source,js]
124133
----
134+
// Sample user database
135+
const userDb = {
136+
"johnsmith": {
137+
"id": "johnsmith",
138+
"name": "John Smith",
139+
"fullName": "John Smith",
140+
"description": "Company Founder",
141+
"image": "https://i.pravatar.cc/150?img=11"
142+
},
143+
"jennynichols": {
144+
"id": "jennynichols",
145+
"name": "Jenny Nichols",
146+
"fullName": "Jenny Nichols",
147+
"description": "Marketing Director",
148+
"image": "https://i.pravatar.cc/150?img=10"
149+
}
150+
};
151+
125152
const comments = tinymce.activeEditor.plugins.tinycomments;
126153
127154
console.log(comments.getEventLog());
@@ -131,11 +158,19 @@ console.log(comments.getEventLog(
131158
132159
const eventLog = comments.getEventLog();
133160
const events = eventLog.events;
134-
const mentionedUsers = events.flatMap(({ mentionedUids }) => mentionedUids || []);
161+
162+
// Ensure that the mentioned users are valid users in the database
163+
const validatedEvents = JSON.parse(JSON.stringify(events));
164+
validatedEvents.forEach((event) => {
165+
// Filter out invalid users - change this to your own validation logic
166+
event.mentionedUids = event.mentionedUids ? event.mentionedUids.filter((uid) => userDb[uid]) : undefined;
167+
});
168+
169+
const mentionedUsers = validatedEvents.flatMap(({ mentionedUids }) => mentionedUids || []);
135170
console.log(mentionedUsers);
136171
137172
let whoMentionedWho = {};
138-
events.forEach((event) => {
173+
validatedEvents.forEach((event) => {
139174
if ((event.type === "create" || event.type === "reply") && event.mentionedUids !== undefined) {
140175
console.log(event);
141176
if (whoMentionedWho[event.conversationAuthor.author] === undefined) {

0 commit comments

Comments
 (0)