Skip to content

Commit 3afd211

Browse files
authored
DOC-3147: New User Lookup API for retrieving and caching user details. (#3801)
* DOC-3147: New User Lookup API for retrieving and caching user details. * Update modules/ROOT/pages/8.0-release-notes.adoc
1 parent 1da3634 commit 3afd211

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

modules/ROOT/pages/8.0-release-notes.adoc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,68 @@ The `+chevronTooltip+` property provides custom tooltip text for the chevron but
351351

352352
For more information, see xref:custom-split-toolbar-button.adoc[Split toolbar buttons].
353353

354+
=== New User Lookup API for retrieving and caching user details
355+
// #TINY-11974
356+
357+
{productname} {release-version} introduces a new xref:userlookup.adoc[User Lookup API] that enables integrations to retrieve and cache user details (such as names and avatars) and identify the current user within the editor. This API is particularly useful when building features that rely on user context, such as commenting systems or displaying lists of elements containing user information.
358+
359+
The User Lookup API provides efficient user data management with built-in caching, reducing redundant network requests and improving performance. It can be used as a universal solution for `+<pluginname>_author+` and `+<pluginname>_author_avatar+` configurations across various plugins, including currently supported plugins such as **Suggested Edits**, **Comments**, and **Revision History**.
360+
361+
Key features include:
362+
363+
* **Current user identification**: Set and retrieve the active user's ID using the new xref:userlookup.adoc#user_id[`user_id`] configuration option
364+
* **Flexible user fetching**: Configure custom user data retrieval through the xref:userlookup.adoc#fetch_users[`fetch_users`] callback function
365+
* **Built-in caching**: Automatic caching of user data to minimize API calls
366+
* **Fallback handling**: Automatic generation of default user information when custom fetch functions are not provided
367+
* **Extensible user objects**: Support for custom metadata through the `custom` property
368+
369+
==== Basic configuration
370+
371+
The API requires two main configuration options:
372+
373+
[source,js]
374+
----
375+
tinymce.init({
376+
selector: 'textarea',
377+
user_id: 'alextaylor', // Set the current user's unique identifier
378+
fetch_users: (userIds) => {
379+
// Return a Promise that resolves to an array of user objects
380+
return Promise.all(
381+
userIds.map(userId =>
382+
fetch(`/users/${userId}`)
383+
.then(response => response.json())
384+
.catch(() => ({ id: userId })) // Fallback for failed requests
385+
)
386+
);
387+
}
388+
});
389+
----
390+
391+
==== API usage
392+
393+
Once configured, the API provides two main methods:
394+
395+
* `editor.userLookup.userId` - Returns the current user's ID
396+
* `editor.userLookup.fetchUsers(userIds)` - Fetches and caches user information
397+
398+
[source,js]
399+
----
400+
editor.on('init', () => {
401+
// Get current user ID
402+
console.log('Current user:', editor.userLookup.userId);
403+
404+
// Fetch multiple users
405+
const users = editor.userLookup.fetchUsers(['user-1', 'user-2']);
406+
407+
// Handle individual user promises
408+
users['user-1'].then(user => {
409+
console.log('User 1 name:', user.name);
410+
});
411+
});
412+
----
413+
414+
For comprehensive documentation and examples, see: xref:userlookup.adoc[User Lookup API].
415+
354416
[[changes]]
355417
== Changes
356418

0 commit comments

Comments
 (0)