Query Chatroom Information
You can use the getChatRoomInfo method under RongChatRoomClient to retrieve chatroom information, which returns the following data:
- Total number of chatroom members
- A list of specified chatroom members (up to 20), including each member's user ID and join time
tip
Rate Limit: A single device can call this method once per second, with a maximum of 20 calls per minute per device.
Interface
RongChatRoomClient.getInstance().getChatRoomInfo(chatroomId, defMemberCount, ChatRoomMemberOrder.RC_CHAT_ROOM_MEMBER_ASC, callback);
Parameter Description
| Parameter | Type | Description |
|---|---|---|
chatRoomId | String | Chatroom ID |
defMemberCount | Int | Number of chatroom members to retrieve. Range: 0-20. Since chatrooms typically have a large number of members, the upper limit is set to 20 for efficiency and user experience. If count is 0, the returned chatroom information will only include the total member count, not the specific member list. |
order | ChatRoomMemberOrder | The order in which chatroom members are returned. RC_CHAT_ROOM_MEMBER_ASC (ascending) retrieves members from earliest to latest join time, returning the earliest joined members. RC_CHAT_ROOM_MEMBER_DESC (descending) retrieves members from latest to earliest join time, returning the most recently joined members. |
callback | ResultCallback<ChatRoomInfo> | Callback interface. On success, returns ChatRoomInfo, which contains the chatroom member list as requested. Each list element is a chatroom member object ChatRoomMemberInfo, including the user ID (userId) and join time (joinTime) in Unix timestamp format (milliseconds). Members are listed in chronological order from oldest to newest. |
Example Code
String chatroomId = "Chatroom Target ID";
int defMemberCount = 10;
RongChatRoomClient.getInstance().getChatRoomInfo(chatroomId, defMemberCount, ChatRoomMemberOrder.RC_CHAT_ROOM_MEMBER_ASC, new IRongCoreCallback.ResultCallback<ChatRoomInfo>() {
@Override
public void onSuccess(ChatRoomInfo chatRoomInfo) {
// Get ChatRoomInfo properties
String chatRoomId = chatRoomInfo.getChatRoomId();
int totalMemberCount = chatRoomInfo.getTotalMemberCount();
// Get ChatRoomMemberInfo properties
List<ChatRoomMemberInfo> memberInfoList = chatRoomInfo.getMemberInfo();
if (memberInfoList != null) {
for (ChatRoomMemberInfo memberInfo : memberInfoList) {
String MemberId = memberInfo.getUserId();
long JoinTime = memberInfo.getJoinTime();
}
}
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Handle error
}
});