Query Chatroom Information
You can retrieve chatroom information through the IMLib SDK:
- Total number of chatroom members.
- A list of specified chatroom members (up to 20), including each member's userId and their join time.
tip
Rate Limit: Each device can call this API once per second, with a maximum of 20 calls per minute per device.
Interface Prototype
- (void)getChatRoomInfo:(NSString *)targetId
count:(int)count
order:(RCChatRoomMemberOrder)order
success:(nullable void (^)(RCChatRoomInfo *chatRoomInfo))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| targetId | NSString | Chatroom ID. Maximum valid length is 64 characters. |
| count | 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 without the member list. |
| order | RCChatRoomMemberOrder | Order of the retrieved member list (earliest or latest joined members). RC_ChatRoom_Member_Asc (1) indicates ascending order, retrieving members from earliest join time; RC_ChatRoom_Member_Desc (2) indicates descending order, retrieving members from latest join time. |
| successBlock | Block | Success callback. Returns RCChatRoomInfo, which contains the chatroom member list as requested. See RCChatRoomInfo Class Description below. |
| errorBlock | Block | Failure callback. Returns an error code RCErrorCode in status. |
-
RCChatRoomInfo Class Description:
Parameter Type Description targetId NSString Chatroom information memberOrder RCChatRoomMemberOrder Order of the retrieved member list memberInfoArray NSArray Chatroom member list. The array elements are chatroom member objects RCChatRoomMemberInfo, containing the user ID ( userId) and join time (joinTime) in Unix timestamp format (milliseconds). Members are listed in chronological order of joining.totalMemberCount int Total number of members in the chatroom
Example Code
[[RCChatRoomClient sharedChatRoomClient] getChatRoomInfo:@"chatroomId"
count:0
order:RC_ChatRoom_Member_Asc
success:^(RCChatRoomInfo *chatRoomInfo) {
// Get ChatRoomInfo properties
NSString *targetId = chatRoomInfo.targetId;
int totalMemberCount = chatRoomInfo.totalMemberCount;
NSArray<RCChatRoomMemberInfo *> *memberInfoArray = chatRoomInfo.memberInfoArray;
// Get ChatRoomMemberInfo properties
for (RCChatRoomMemberInfo *memberInfo in memberInfoArray) {
NSString *userId = memberInfo.userId;
long long joinTime = memberInfo.joinTime;
// TODO
}
}
error:^(RCErrorCode status) {
// Handle error
}];