public class RoomApi extends Object
限定符和类型 | 方法和说明 |
---|---|
reactor.core.publisher.Mono<Void> |
addRoomMember(String roomId,
String username)
m
向聊天室添加成员。
|
reactor.core.publisher.Mono<Void> |
assignRoom(String chatroomId,
String newOwner)
转让聊天室。
|
reactor.core.publisher.Mono<String> |
createRoom(String name,
String description,
String owner,
List<String> members,
int maxMembers)
创建聊天室。
|
reactor.core.publisher.Mono<String> |
createRoom(String name,
String description,
String owner,
List<String> members,
int maxMembers,
String custom)
创建聊天室。
|
reactor.core.publisher.Mono<String> |
createRoom(String name,
String description,
String owner,
List<String> members,
int maxMembers,
String custom,
Boolean needVerify)
创建聊天室。
|
reactor.core.publisher.Mono<Void> |
demoteRoomAdmin(String roomId,
String username)
降级聊天室管理员至成员。
|
reactor.core.publisher.Mono<Void> |
demoteRoomSuperAdmin(String username)
降级超级管理员为普通用户
API使用示例:
EMService service;
try {
service.room().demoteRoomSuperAdmin("username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
|
reactor.core.publisher.Mono<Void> |
destroyRoom(String roomId)
注销聊天室
请谨慎使用。
|
reactor.core.publisher.Mono<EMRoom> |
getRoom(String id)
获取聊天室详情。
|
reactor.core.publisher.Mono<String> |
getRoomAnnouncement(String chatroomId)
获取聊天室公告。
|
reactor.core.publisher.Mono<List<EMRoom>> |
getRoomList(List<String> roomIdList)
获取多个聊天室详情。
|
reactor.core.publisher.Flux<String> |
listRoomAdminsAll(String roomId)
获取聊天室管理员。
|
reactor.core.publisher.Mono<EMPage<String>> |
listRoomMembers(String roomId,
int limit,
String cursor)
分页获取聊天室成员列表。
|
reactor.core.publisher.Mono<EMPage<String>> |
listRoomMembers(String roomId,
int limit,
String cursor,
String sort)
分页获取聊天室成员列表。
|
reactor.core.publisher.Flux<String> |
listRoomMembersAll(String roomId)
获取聊天室全部成员列表。
|
reactor.core.publisher.Flux<String> |
listRoomMembersAll(String roomId,
String sort)
获取聊天室全部成员列表。
|
reactor.core.publisher.Flux<Map<String,String>> |
listRoomMembersAllWithOwner(String roomId)
获取聊天室全部成员列表,包括聊天室的 Owner。
|
reactor.core.publisher.Mono<List<Map<String,String>>> |
listRoomMembersWithOwner(String roomId,
int pageNum,
int pageSize)
分页获取聊天室成员列表,包括聊天室的 Owner。
|
reactor.core.publisher.Mono<EMPage<String>> |
listRooms(int limit,
String cursor)
分页获取聊天室列表
API使用示例:
EMService service;
EMPage
|
reactor.core.publisher.Flux<String> |
listRoomsAll()
获取全部聊天室列表
API使用示例:
EMService service;
try {
List<String> rooms = service.room().listRoomsAll().collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
|
reactor.core.publisher.Flux<String> |
listRoomSuperAdminsAll()
获取所有超级管理员列表。
|
reactor.core.publisher.Flux<String> |
listRoomsUserJoined(String username)
获取用户加入的聊天室列表。
|
reactor.core.publisher.Mono<Void> |
promoteRoomAdmin(String roomId,
String username)
升级聊天室成员至管理员。
|
reactor.core.publisher.Mono<Void> |
promoteRoomSuperAdmin(String username)
升级用户为超级管理员,只有超级管理员有权限创建聊天室。
|
reactor.core.publisher.Mono<Void> |
removeRoomMember(String roomId,
String username)
从聊天室移除成员。
|
reactor.core.publisher.Mono<Void> |
updateRoom(String id,
Consumer<UpdateRoomRequest> customizer)
修改聊天室。
|
reactor.core.publisher.Mono<Void> |
updateRoomAnnouncement(String chatroomId,
String announcement)
更新聊天室公告。
|
public RoomApi(Context context)
public reactor.core.publisher.Mono<String> createRoom(String name, String description, String owner, List<String> members, int maxMembers)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String roomId = service.room().createRoom("name", "description", "owner", members, 200).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
name
- 聊天室名称description
- 聊天室描述owner
- 聊天室主members
- 聊天室初始成员的用户名列表maxMembers
- 聊天室最大成员数public reactor.core.publisher.Mono<String> createRoom(String name, String description, String owner, List<String> members, int maxMembers, String custom)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String roomId = service.room().createRoom("name", "description", "owner", members, 200).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
name
- 聊天室名称description
- 聊天室描述owner
- 聊天室主members
- 聊天室初始成员的用户名列表maxMembers
- 聊天室最大成员数custom
- 聊天室扩展信息,例如可以给聊天室添加业务相关的标记public reactor.core.publisher.Mono<String> createRoom(String name, String description, String owner, List<String> members, int maxMembers, String custom, Boolean needVerify)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String roomId = service.room().createRoom("name", "description", "owner", members, 200, "custom", true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
name
- 聊天室名称description
- 聊天室描述owner
- 聊天室主members
- 聊天室初始成员的用户名列表maxMembers
- 聊天室最大成员数custom
- 聊天室扩展信息,例如可以给聊天室添加业务相关的标记needVerify
- 是否审核聊天室名称(付费功能,需联系商务开通)public reactor.core.publisher.Mono<EMRoom> getRoom(String id)
API使用示例:
EMService service;
try {
EMRoom room = service.room().getRoom(roomId).block();
String roomName = room.name();
String roomDescription = room.description();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
id
- 聊天室idpublic reactor.core.publisher.Mono<List<EMRoom>> getRoomList(List<String> roomIdList)
API使用示例:
EMService service;
try {
List<String> roomIdList = new ArrayList<>();
roomIdList.add("193100825821185");
roomIdList.add("193100825821186");
List<EMRoom> roomList = service.group().getRoomList(roomIdList).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomIdList
- 聊天室id列表public reactor.core.publisher.Mono<Void> updateRoom(String id, Consumer<UpdateRoomRequest> customizer)
可修改的字段参考 UpdateRoomRequest
API使用示例:
比如,要更新聊天室名称,可以这么做:
EMService service;
try {
service.updateRoom(roomId, request -> request.withName("some cool name")).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
id
- 聊天室idcustomizer
- 更新请求定制函数UpdateRoomRequest
,
修改聊天室public reactor.core.publisher.Flux<String> listRoomsAll()
API使用示例:
EMService service;
try {
List<String> rooms = service.room().listRoomsAll().collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
public reactor.core.publisher.Mono<EMPage<String>> listRooms(int limit, String cursor)
API使用示例:
EMService service;
EMPage<String> page = null;
try {
service.room().listRooms(10, null).block();
List<String> roomIds = page.getValues();
System.out.println("聊天室列表:" + roomIds);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
// ... do something with the roomIds ...
if (page != null) {
String cursor = page.getCursor();
// cursor == null indicates the end of the list
while (cursor != null) {
try {
page = service.room().listRooms(10, cursor).block();
System.out.println("聊天室列表:" + page.getValues());
// ... do something to the roomIds ...
cursor = page.getCursor();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
}
}
limit
- 返回多少个聊天室idcursor
- 开始位置public reactor.core.publisher.Flux<String> listRoomsUserJoined(String username)
API使用示例:
EMService service;
try {
List<String> rooms = service.room().listRoomsUserJoined("username").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 用户名public reactor.core.publisher.Flux<String> listRoomMembersAll(String roomId)
API使用示例:
EMService service;
try {
List<String> members = service.room().listRoomMembersAll("roomId").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idpublic reactor.core.publisher.Flux<String> listRoomMembersAll(String roomId, String sort)
API使用示例:
EMService service;
try {
List<String> members = service.room().listRoomMembersAll("roomId", "asc").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idsort
- 聊天室成员排序方法 asc:根据加入顺序升序排序 desc:根据加入顺序降序排序public reactor.core.publisher.Flux<Map<String,String>> listRoomMembersAllWithOwner(String roomId)
API使用示例:
EMService service;
try {
List<Map<String, String>> members = service.room().listRoomMembersAllWithOwner("roomId").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idpublic reactor.core.publisher.Mono<EMPage<String>> listRoomMembers(String roomId, int limit, String cursor)
API使用示例:
EMService service;
EMPage<String> page = null;
try {
EMPage<String> page = service.room().listRoomMembers(roomId, 1, null).block();
List<String> members = page.getValues();
System.out.println("聊天室成员列表:" + members);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
// ... do something with the roomIds ...
if (page != null) {
String cursor = page.getCursor();
// cursor == null indicates the end of the list
while (cursor != null) {
try {
page = service.room().listRoomMembers(roomId, 1, cursor).block();
System.out.println("聊天室成员列表:" + page.getValues());
// ... do something to the members ...
cursor = page.getCursor();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
}
}
roomId
- 聊天室idlimit
- 返回多少个聊天室成员cursor
- 开始位置public reactor.core.publisher.Mono<List<Map<String,String>>> listRoomMembersWithOwner(String roomId, int pageNum, int pageSize)
API使用示例:
EMService service;
EMPage<String> page = null;
try {
List<Map<String, String>> members = service.room().listRoomMembers(roomId, 1, 10).block();
System.out.println("聊天室成员列表:" + members);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idpageNum
- 当前页码。默认从第 1 页开始获取pageSize
- 每页期望返回的群组成员数量。取值范围为[1,100]。默认为 10。public reactor.core.publisher.Mono<EMPage<String>> listRoomMembers(String roomId, int limit, String cursor, String sort)
API使用示例:
EMService service;
EMPage<String> page = null;
try {
EMPage<String> page = service.room().listRoomMembers(roomId, 1, null, "asc").block();
List<String> members = page.getValues();
System.out.println("聊天室成员列表:" + members);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
// ... do something with the roomIds ...
if (page != null) {
String cursor = page.getCursor();
// cursor == null indicates the end of the list
while (cursor != null) {
try {
page = service.room().listRoomMembers(roomId, 1, cursor, "asc").block();
System.out.println("聊天室成员列表:" + page.getValues());
// ... do something to the members ...
cursor = page.getCursor();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
}
}
roomId
- 聊天室idlimit
- 返回多少个聊天室成员cursor
- 开始位置sort
- 聊天室成员排序方法 asc:根据加入顺序升序排序 desc:根据加入顺序降序排序public reactor.core.publisher.Mono<Void> addRoomMember(String roomId, String username)
API使用示例:
EMService service;
try {
service.room().addRoomMember("roomId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idusername
- 要添加的用户的用户名public reactor.core.publisher.Mono<Void> removeRoomMember(String roomId, String username)
API使用示例:
EMService service;
try {
service.room().removeRoomMember("roomId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idusername
- 要移除的成员的用户名public reactor.core.publisher.Flux<String> listRoomAdminsAll(String roomId)
API使用示例:
EMService service;
try {
List<String> admins = service.room().listRoomAdminsAll("roomId").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idpublic reactor.core.publisher.Mono<Void> promoteRoomAdmin(String roomId, String username)
API使用示例:
EMService service;
try {
service.room().promoteRoomAdmin("roomId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idusername
- 要升级的成员的用户名public reactor.core.publisher.Mono<Void> demoteRoomAdmin(String roomId, String username)
API使用示例:
EMService service;
try {
service.room().demoteRoomAdmin("roomId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idusername
- 要降级的管理员的用户名public reactor.core.publisher.Flux<String> listRoomSuperAdminsAll()
API使用示例:
EMService service;
try {
List<String> superAdmins = service.room().listRoomSuperAdminsAll().collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
public reactor.core.publisher.Mono<Void> promoteRoomSuperAdmin(String username)
API使用示例:
EMService service;
try {
service.room().promoteRoomSuperAdmin("username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 要升级的用户的用户名public reactor.core.publisher.Mono<Void> demoteRoomSuperAdmin(String username)
API使用示例:
EMService service;
try {
service.room().demoteRoomSuperAdmin("username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- 要降级的超级管理员的用户名public reactor.core.publisher.Mono<Void> destroyRoom(String roomId)
请谨慎使用。
API使用示例:
EMService service;
try {
service.room().destroyRoom("roomId").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
roomId
- 聊天室idpublic reactor.core.publisher.Mono<Void> assignRoom(String chatroomId, String newOwner)
API使用示例:
EMService service;
try {
service.room().assignRoom("chatroomId", "newOwner").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
chatroomId
- 聊天室idnewOwner
- 被转让聊天室的用户名public reactor.core.publisher.Mono<String> getRoomAnnouncement(String chatroomId)
API使用示例:
EMService service;
try {
String roomAnnouncement = service.room().getRoomAnnouncement("roomId").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
chatroomId
- 聊天室idpublic reactor.core.publisher.Mono<Void> updateRoomAnnouncement(String chatroomId, String announcement)
API使用示例:
EMService service;
try {
service.room().updateRoomAnnouncement("chatroomId", "announcement").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
chatroomId
- 聊天室idannouncement
- 聊天室公告Copyright © 2024. All rights reserved.