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 null
, it indicates that the user is not logged in and you need to log the user into CometChat.
User
object containing all the information related to the logged-in user.
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.
The UsersRequestBuilder
class allows you to set the below parameters:
Set Limit
This method sets the limit i.e. the number of users that should be fetched in a single iteration.Set Search Keyword
This method allows you to set the search string based on which the users are to be fetched.Set Status
The status based on which the users are to be fetched. The status parameter can contain one of the below two values:- CometChatUserStatus.online - will return the list of only online users.
- CometChatUserStatus.offline - will return the list of only offline users.
Hide Blocked Users
This method is used to determine if the blocked users should be returned as a part of the user list. If set totrue
, the user list will not contain the users blocked by the logged-in user.
Set Roles
This method allows you to fetch the users based on multiple roles.Friends Only
This property when set to true will return only the friends of the logged-in user.Set Tags
This method accepts a list of tags based on which the list of users is to be fetched. The list fetched will only contain the users that have been tagged with the specified tags.With Tags
This property when set to true will fetch tags data along with the list of users.Set UIDs
This method accepts a list of UIDs based on which the list of users is fetched. A maximum of 25 users can be fetched.build()
method to get the object of the UsersRequest
class.
Once you have the object of the UsersRequest
class, you need to call the fetchNext()
method. Calling this method will return a list of User
objects containing ‘n’ number of users depending on the limit set.
Retrieve Particular User Details
To get the information of a user, you can use thegetUser()
method.
getUser()
method takes the following parameters:
Parameter | Description |
---|---|
UID | The UID of the user for whom the details are to be fetched |
User
object containing the details of the user is returned.
Get online user count
To get the total count of online users for your app, you can use thegetOnlineUserCount()
method.