====== 聊天室管理 ======
----
环信聊天室模型支持最大成员数为5000,和群组不同,聊天室内成员离线后,服务器当监听到此成员不在线后不再会给此成员再发推送。
* 支持最大成员5000;
* 环信的聊天室内仅有 owner 和游客;
* 不支持客户端建立聊天室;
* 不支持客户端邀请;
* 不支持 REST 邀请。
===== 服务器端 =====
==== 创建聊天室 ====
curl -X POST “http://a1.easemob.com/easemob-demo/chatdemoui/chatrooms” -H “Authorization: Bearer ${token}” -d ‘{“owner”:”u1”,”members”:[“u1”,”u2”],”maxusers”:5000,”groupname”:”chatroom title”,”desc”:”chatroom description”}”
==== 查询所有 APP 聊天室 ====
curl -X GET “http://a1.easemob.com/easemob-demo/chatdemoui/chatrooms” -H “Authorization: Bearer ${token}”
==== 查询聊天室详情 ====
curl -X GET “http://a1.easemob.com/easemob-demo/chatdemoui/chatrooms/1430798028680235” -H “Authorization: Bearer ${token}”
==== 聊天室踢人 ====
curl -X DELETE ‘https://a1.easemob.com/easemob-demo/chatdemoui/chatrooms/1430798028680235/users/u2’ -H “Authorization: Bearer ${token}”
==== 删除聊天室 ====
curl -X DELETE ‘https://a1.easemob.com/easemob-demo/chatdemoui/chatrooms/143228117786605’ -H “Authorization: Bearer ${token}”
更多服务器端 REST 操作请参考[[im:server:basics:chatroom|聊天室管理]]。
===== 客户端 =====
* 支持查询所有 APP 聊天室;
* 支持查询聊天室详情;
* 加入聊天室;
* 退出聊天室;
==== 加入聊天室 ====
//id为聊天室ID
EMError error;
string id = getStringAttrFromJson(json, "id");
if (!id.empty())
{
g_client->getChatroomManager().joinChatroom(id, error);
if (error.mErrorCode != EMError::EM_NO_ERROR)
{
callback->Failure(error.mErrorCode, error.mDescription);
}
else
{
callback->Success(id);
}
}
**注意:**对于聊天室模型,请一定要等到 Join 回调成功后再去初始化 conversation。
==== 离开聊天室 ====
EMError error;
string id = getStringAttrFromJson(json, "id");
if (!id.empty())
{
g_client->getChatroomManager().leaveChatroom(id, error);
if (error.mErrorCode != EMError::EM_NO_ERROR)
{
callback->Failure(error.mErrorCode, error.mDescription);
}
else
{
callback->Success(id);
}
}
==== 获取聊天室列表 ====
EMError error;
EMChatroomList roomList = g_client->getChatroomManager().fetchAllChatrooms(error);
string ret;
if (error.mErrorCode == EMError::EM_NO_ERROR) {
for (EMChatroomPtr room : roomList)
{
ret += "{\"owner\":\"";
ret += room->owner();
ret += "\",\"name\":\"";
ret += room->chatroomSubject();
ret += "\",\"id\":\"";
ret += room->chatroomId();
ret += "\",\"affiliations_count\":";
ret += "5";
ret += "},";
}
if (!ret.empty())
{
string tmp = ret.substr(0, ret.length() - 1);
ret = "[" + tmp + "]";
}
callback->Success(ret);
}
else
{
callback->Failure(error.mErrorCode, error.mDescription);
}
----
上一页:[[im:windows:basics:group|群组管理]]
下一页:[[im:windows:log:releasenote|Windows SDK更新日志]]