AI Integration Quick Reference
AI Integration Quick Reference
Retrieve Logged In User Details
You can get the details of the logged-in user using thegetLoggedInUser() method. This method can also be used to check if the user is logged in or not. If the method returns Promise with reject callback, it indicates that the user is not logged in and you need to log the user into CometChat SDK.
- Get Logged In User Details
User objects.
User Object Fields
Get the Logged-In User
UsegetLoggedinUser() to get the current user’s details. Resolves with null if no user is logged in.
- TypeScript
- JavaScript
User object with the logged-in user’s information
Retrieve List of Users
In order to fetch the list of users, you can use theUsersRequest class. To use this class i.e to create an object of the UsersRequest class, you need to use the UsersRequestBuilder class. The UsersRequestBuilder class allows you to set the parameters based on which the users are to be fetched.
Fetching using this builder will return User objects
The UsersRequestBuilder class allows you to set the below parameters:
Set Limit
Sets the number of users to fetch per request.- TypeScript
- JavaScript
Set Search Keyword
With offline support on, this filter is answered by the server only; the cached page is empty.
- TypeScript
- JavaScript
Search In
With offline support on, this filter is answered by the server only; the cached page is empty.
setSearchKeyword(). By default, searches both UID and name.
- TypeScript
- JavaScript
Set Status
With offline support on, this filter is answered by the server only; the cached page is empty.
CometChat.USER_STATUS.ONLINE— Only online usersCometChat.USER_STATUS.OFFLINE— Only offline users
- TypeScript
- JavaScript
Hide Blocked Users
Whentrue, excludes users blocked by the logged-in user from the results.
- TypeScript
- JavaScript
Set Roles
Filters users by specified roles.- TypeScript
- JavaScript
Friends Only
Whentrue, returns only friends of the logged-in user.
- TypeScript
- JavaScript
Set Tags
Filters users by specified tags.- TypeScript
- JavaScript
With Tags
Whentrue, includes tag data in the returned user objects.
- TypeScript
- JavaScript
Set UIDs
Fetches specific users by their UIDs. Maximum 25 users per request.- TypeScript
- JavaScript
Sort By
Sorts the user list by a specific property. Default sort order:status → name → UID. Pass "name" to sort by name → UID.
- TypeScript
- JavaScript
Sort By Order
Sets the sort order. Default is ascending ("asc"). Use "desc" for descending.
- TypeScript
- JavaScript
build() to get the UsersRequest object, then call fetchNext() to retrieve users.
- TypeScript
- JavaScript
fetchNext() method returns an array of User objects.
Retrieve Particular User Details
UsegetUser() to fetch a specific user’s details by UID.
- TypeScript
- JavaScript
It returns the
User object containing the details of the user.
Get Online User Count
UsegetOnlineUserCount() to get the total number of online users in your app.
- TypeScript
- JavaScript
Offline Behaviour
With offline support enabled,UsersRequest.fetchNext() accepts a UserFetchListener and first delivers onCachedUsers from the device (the pages the server last returned for this exact request, replayed on-device, empty when nothing was recorded), then onServerUsers with the live page to reconcile by uid. Offline, the read ends with onError with code FAILED_TO_FETCH after the cached page. A request that uses a server-only filter records nothing, so its cached page is always empty. See Show Cached Data.
Next Steps
User Presence
Track and subscribe to user online/offline status
Block Users
Block and unblock users from your application
User Management
Create, update, and delete users programmatically
Retrieve Conversations
Fetch conversation lists for your chat UI