Skip to main content
The CometChat SDK provides methods to retrieve the logged-in user, fetch filtered user lists, look up individual users by UID, and get online user counts. All user methods return User objects.
Available via: SDK | REST API | UI Kits

User Object Fields

Retrieve Logged In User Details

Use getLoggedInUser() to get the current user’s details. Returns null if no user is logged in.
This method returns a User object with the logged-in user’s information.

Retrieve List of Users

In order to fetch the list of users, you can use the UsersRequest 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.

UsersRequestBuilder Parameters

The UsersRequestBuilder class allows you to set the below parameters:

Set Limit

Sets the number of users to fetch per request.

Set Search Keyword

Filters users by a search string.

Search In

Specifies which user properties to search. Works with searchKeyword. By default, searches both UID and name.

Set Status

Filters users by online status:
  • CometChatUserStatus.online — Only online users
  • CometChatUserStatus.offline — Only offline users
If not set, returns all users.

Hide Blocked Users

When true, excludes users blocked by the logged-in user from the results.

Set Roles

Filters users by specified roles.

Friends Only

When true, returns only friends of the logged-in user.

Set Tags

Filters users by specified tags.

With Tags

When true, includes tag data in the returned user objects.

Set UIDs

Fetches specific users by their UIDs. Maximum 25 users per request.

Sort By

Sorts the user list by a specific property. Default sort order: status → name → UID. Pass "name" to sort by name → UID.

Sort By Order

Sets the sort order. Default is ascending ("asc"). Use "desc" for descending.
After configuring the builder, call build() to get the UsersRequest object, then call fetchNext() to retrieve users.
The fetchNext() method returns a list of User objects.
On Success — A list of User objects matching the request filters. Each item in the list contains:User Object:

Retrieve Particular User Details

Use getUser() to fetch a specific user’s details by UID.
The getUser() method takes the following parameters: On success, the User object containing the details of the user is returned.
On Success — A User object containing the details of the requested user:User Object:

Get Online User Count

Use getOnlineUserCount() to get the total number of online users in your app.
getOnlineUserCount() resolves with an int representing the total count of currently online users in your app.
On Success — An int value representing the total count of online users:

Next Steps

User Presence

Monitor and manage real-time user online/offline status

Block Users

Block and unblock users to control interactions

User Management

Create, update, and delete users programmatically

Users Overview

Explore all user-related features and capabilities