public class GroupApi extends Object
限定符和类型 | 方法和说明 |
---|---|
reactor.core.publisher.Mono<Void> |
addGroupAdmin(String groupId,
String username)
升级群成员为群管理员。
|
reactor.core.publisher.Mono<Void> |
addGroupMember(String groupId,
String username)
添加群成员(单个)。
|
reactor.core.publisher.Mono<Void> |
addGroupMembers(String groupId,
List<String> usernames)
添加群成员(多个)。
|
reactor.core.publisher.Mono<Void> |
assignGroup(String groupId,
String newOwner)
转让群组。
|
reactor.core.publisher.Mono<String> |
createLargePrivateGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean canMemberInvite,
boolean needApproveToJoin,
boolean needInviteConfirm,
String custom,
boolean needVerify,
String avatar)
创建大型私有群。
|
reactor.core.publisher.Mono<String> |
createLargePrivateGroup(String groupId,
String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean canMemberInvite,
boolean needApproveToJoin,
boolean needInviteConfirm,
String custom,
boolean needVerify,
String avatar)
指定群组ID,创建大型私有群。
|
reactor.core.publisher.Mono<String> |
createLargePublicGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean needApproveToJoin,
String custom,
boolean needVerify,
String avatar)
创建大型公开群。
|
reactor.core.publisher.Mono<String> |
createLargePublicGroup(String groupId,
String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean needApproveToJoin,
String custom,
boolean needVerify,
String avatar)
指定群组ID,创建大型公开群。
|
reactor.core.publisher.Mono<String> |
createPrivateGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean canMemberInvite)
创建私有群。
|
reactor.core.publisher.Mono<String> |
createPrivateGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean canMemberInvite,
boolean needApproveToJoin,
boolean needInviteConfirm,
String custom)
创建私有群。
|
reactor.core.publisher.Mono<String> |
createPrivateGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean canMemberInvite,
boolean needApproveToJoin,
boolean needInviteConfirm,
String custom,
boolean needVerify,
String avatar)
创建私有群。
|
reactor.core.publisher.Mono<String> |
createPrivateGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean canMemberInvite,
String custom)
创建私有群。
|
reactor.core.publisher.Mono<String> |
createPrivateGroup(String groupId,
String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean canMemberInvite,
boolean needApproveToJoin,
boolean needInviteConfirm,
String custom,
boolean needVerify,
String avatar)
指定群组ID,创建私有群。
|
reactor.core.publisher.Mono<String> |
createPublicGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean needApproveToJoin)
创建公开群。
|
reactor.core.publisher.Mono<String> |
createPublicGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean needApproveToJoin,
String custom)
创建公开群。
|
reactor.core.publisher.Mono<String> |
createPublicGroup(String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean needApproveToJoin,
String custom,
boolean needVerify,
String avatar)
创建公开群。
|
reactor.core.publisher.Mono<String> |
createPublicGroup(String groupId,
String owner,
String groupName,
String description,
List<String> members,
int maxMembers,
boolean needApproveToJoin,
String custom,
boolean needVerify,
String avatar)
指定群组ID,创建公开群。
|
reactor.core.publisher.Mono<Void> |
destroyGroup(String groupId)
注销群。
|
reactor.core.publisher.Mono<Boolean> |
disableGroup(String groupId)
封禁群组
封禁指定的群组。
|
reactor.core.publisher.Mono<Boolean> |
enableGroup(String groupId)
解禁群组
解除对指定群组的封禁。
|
reactor.core.publisher.Mono<EMGroup> |
getGroup(String groupId)
获取群详情。
|
reactor.core.publisher.Mono<String> |
getGroupAnnouncement(String groupId)
获取群公告。
|
reactor.core.publisher.Mono<List<EMGroup>> |
getGroupList(List<String> groupIdList)
获取多个群详情。
|
reactor.core.publisher.Flux<String> |
listAllGroupMembers(String groupId)
获取群全部成员,不包括群组的 Owner。
|
reactor.core.publisher.Flux<String> |
listAllGroupMembers(String groupId,
String sort)
获取群全部成员,不包括群组的 Owner。
|
reactor.core.publisher.Flux<Map<String,String>> |
listAllGroupMembersIncludeOwner(String groupId,
String sort)
获取群全部成员,包括群组的 Owner。
|
reactor.core.publisher.Flux<String> |
listAllGroups()
获取全部群列表。
|
reactor.core.publisher.Flux<GroupResource> |
listAllGroupsWithInfo()
获取全部群列表,返回值携带群组信息。
|
reactor.core.publisher.Flux<String> |
listGroupAdmins(String groupId)
获取群全部管理员。
|
reactor.core.publisher.Mono<EMPage<String>> |
listGroupMembers(String groupId,
int limit,
String cursor)
分页获取群成员。
|
reactor.core.publisher.Mono<EMPage<String>> |
listGroupMembers(String groupId,
int limit,
String cursor,
String sort)
分页获取群成员。
|
reactor.core.publisher.Mono<List<Map<String,String>>> |
listGroupMembersIncludeOwner(String groupId,
int pageNum,
int pageSize,
String sort)
分页获取群组成员列表,包括群组的 Owner。
|
reactor.core.publisher.Mono<EMPage<String>> |
listGroups(int limit,
String cursor)
分页获取群列表。
|
reactor.core.publisher.Flux<String> |
listGroupsUserJoined(String username)
获取用户加入的所有群组。
|
reactor.core.publisher.Flux<JoinGroupResource> |
listGroupsUserJoinedWithInfo(String username)
获取用户加入的所有群组,返回值携带群组信息。
|
reactor.core.publisher.Mono<List<JoinGroupResource>> |
listGroupsUserJoinedWithInfo(String username,
int pageNum,
int pageSize)
分页获取用户加入的所有群组,返回值携带群组信息。
|
reactor.core.publisher.Mono<EMPage<GroupResource>> |
listGroupsWithInfo(int limit,
String cursor)
分页获取群列表,返回值携带群组信息。
|
reactor.core.publisher.Mono<Void> |
removeGroupAdmin(String groupId,
String username)
降级群管理员为群成员。
|
reactor.core.publisher.Mono<Void> |
removeGroupMember(String groupId,
String username)
移除群成员。
|
reactor.core.publisher.Mono<List<EMRemoveMember>> |
removeGroupMembers(String groupId,
List<String> usernames)
移除群成员(多个)。
|
reactor.core.publisher.Mono<Void> |
updateGroup(String groupId,
Consumer<UpdateGroupRequest> customizer)
修改群详情。
|
reactor.core.publisher.Mono<Void> |
updateGroupAnnouncement(String groupId,
String announcement)
更新群公告。
|
reactor.core.publisher.Mono<Void> |
updateGroupOwner(String groupId,
String username)
修改群主。
|
reactor.core.publisher.Mono<Boolean> |
userIsJoined(String groupId,
String username)
查看指定用户是否已加入群组
API使用示例:
EMService service;
try {
Boolean result = service.group().userIsJoined("groupId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
|
public GroupApi(Context context)
public reactor.core.publisher.Mono<String> createPublicGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean needApproveToJoin)
需要注意的是,目前公开群不允许成员邀请其他用户加入。如果要允许,可以用修改群API设置:
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createPublicGroup("owner", "groupName", "description", members, 200, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数needApproveToJoin
- 新成员加入需要管理员审批public reactor.core.publisher.Mono<String> createPublicGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean needApproveToJoin, String custom)
需要注意的是,目前公开群不允许成员邀请其他用户加入。如果要允许,可以用修改群API设置:
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createPublicGroup("owner", "groupName", "description", members, 200, true, "custom").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
EMService service;
try {
// 修改群组API,允许成员邀请其他用户加入
service.group().updateSetting("group-id", settings -> settings.memberCanInvite(true)).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数needApproveToJoin
- 新成员加入需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createPublicGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean needApproveToJoin, String custom, boolean needVerify, String avatar)
需要注意的是,目前公开群不允许成员邀请其他用户加入。如果要允许,可以用修改群API设置:
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createPublicGroup("owner", "groupName", "description", members, 200, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
EMService service;
try {
// 修改群组API,允许成员邀请其他用户加入
service.group().updateSetting("group-id", settings -> settings.memberCanInvite(true)).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数needApproveToJoin
- 新成员加入需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符。public reactor.core.publisher.Mono<String> createLargePublicGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean needApproveToJoin, String custom, boolean needVerify, String avatar)
大型群,群成员总数超过 3000。大型群不支持离线推送。如需默认创建大型群,请联系环信商务。
需要注意的是,目前公开群不允许成员邀请其他用户加入。如果要允许,可以用修改群API设置:
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createLargePublicGroup("owner", "groupName", "description", , members, 200, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
EMService service;
try {
// 修改群组API,允许成员邀请其他用户加入
service.group().updateSetting("group-id", settings -> settings.memberCanInvite(true)).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数needApproveToJoin
- 新成员加入需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符。public reactor.core.publisher.Mono<String> createPublicGroup(String groupId, String owner, String groupName, String description, List<String> members, int maxMembers, boolean needApproveToJoin, String custom, boolean needVerify, String avatar)
需要注意的是,目前公开群不允许成员邀请其他用户加入。如果要允许,可以用修改群API设置:
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createPublicGroup("groupId", "owner", "groupName", "description", members, 200, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
EMService service;
try {
// 修改群组API,允许成员邀请其他用户加入
service.group().updateSetting("group-id", settings -> settings.memberCanInvite(true)).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组idowner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数needApproveToJoin
- 新成员加入需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createLargePublicGroup(String groupId, String owner, String groupName, String description, List<String> members, int maxMembers, boolean needApproveToJoin, String custom, boolean needVerify, String avatar)
大型群,群成员总数超过 3000。大型群不支持离线推送。如需默认创建大型群,请联系环信商务。
需要注意的是,目前公开群不允许成员邀请其他用户加入。如果要允许,可以用修改群API设置:
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createLargePublicGroup("groupId", "owner", "groupName", "description", members, 200, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
EMService service;
try {
// 修改群组API,允许成员邀请其他用户加入
service.group().updateSetting("group-id", settings -> settings.memberCanInvite(true)).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组idowner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数needApproveToJoin
- 新成员加入需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createPrivateGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean canMemberInvite)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().privateGroup("owner", "groupName", "description", members, 200, true).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数canMemberInvite
- 普通群成员是否允许邀请新用户入群public reactor.core.publisher.Mono<String> createPrivateGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean canMemberInvite, String custom)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().privateGroup("owner", "groupName", "description", members, 200, true, "custom").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数canMemberInvite
- 普通群成员是否允许邀请新用户入群custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createPrivateGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean canMemberInvite, boolean needApproveToJoin, boolean needInviteConfirm, String custom)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().privateGroup("owner", "groupName", "description", members, 200, true, true, true, "custom").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数canMemberInvite
- 普通群成员是否允许邀请新用户入群needInviteConfirm
- 邀请加群,受邀用户是否需要确认needApproveToJoin
- 新成员加入是否需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createPrivateGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean canMemberInvite, boolean needApproveToJoin, boolean needInviteConfirm, String custom, boolean needVerify, String avatar)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().privateGroup("owner", "groupName", "description", members, 200, true, true, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数canMemberInvite
- 普通群成员是否允许邀请新用户入群needInviteConfirm
- 邀请加群,受邀用户是否需要确认needApproveToJoin
- 新成员加入是否需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createLargePrivateGroup(String owner, String groupName, String description, List<String> members, int maxMembers, boolean canMemberInvite, boolean needApproveToJoin, boolean needInviteConfirm, String custom, boolean needVerify, String avatar)
大型群,群成员总数超过 3000。大型群不支持离线推送。如需默认创建大型群,请联系环信商务。
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createLargePrivateGroup("owner", "groupName", "description", members, 200, true, true, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
owner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数canMemberInvite
- 普通群成员是否允许邀请新用户入群needInviteConfirm
- 邀请加群,受邀用户是否需要确认needApproveToJoin
- 新成员加入是否需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createPrivateGroup(String groupId, String owner, String groupName, String description, List<String> members, int maxMembers, boolean canMemberInvite, boolean needApproveToJoin, boolean needInviteConfirm, String custom, boolean needVerify, String avatar)
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().privateGroup("groupId", "owner", "groupName", "description", members, 200, true, true, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组IDowner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数canMemberInvite
- 普通群成员是否允许邀请新用户入群needInviteConfirm
- 邀请加群,受邀用户是否需要确认needApproveToJoin
- 新成员加入是否需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符public reactor.core.publisher.Mono<String> createLargePrivateGroup(String groupId, String owner, String groupName, String description, List<String> members, int maxMembers, boolean canMemberInvite, boolean needApproveToJoin, boolean needInviteConfirm, String custom, boolean needVerify, String avatar)
大型群,群成员总数超过 3000。大型群不支持离线推送。如需默认创建大型群,请联系环信商务。
API使用示例:
EMService service;
List<String> members = new ArrayList<>();
members.add("userA");
try {
String groupId = service.group().createLargePrivateGroup("groupId", "owner", "groupName", "description", members, 200, true, true, true, "custom", true, "http://localhost:8080/image.png").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组IDowner
- 群主的用户名groupName
- 群名,最大长度为 128 字符description
- 群介绍,最大长度为 512 字符members
- 初始群成员的用户名列表maxMembers
- 群最大成员数canMemberInvite
- 普通群成员是否允许邀请新用户入群needInviteConfirm
- 邀请加群,受邀用户是否需要确认needApproveToJoin
- 新成员加入是否需要管理员审批custom
- 群组扩展信息,例如可以给群组添加业务相关的标记,最大长度为 1024 字符needVerify
- 是否审核群名称(付费功能,需联系商务开通)avatar
- 群组头像的 URL,最大长度为 1024 字符public reactor.core.publisher.Mono<Void> destroyGroup(String groupId)
请谨慎使用。
API使用示例:
EMService service;
try {
String groupId = service.group().destroyGroup("groupId").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idpublic reactor.core.publisher.Flux<String> listAllGroups()
API使用示例:
EMService service;
try {
List<String> groups = service.group().listAllGroups().collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
public reactor.core.publisher.Flux<GroupResource> listAllGroupsWithInfo()
API使用示例:
EMService service;
try {
List<GroupResource> groups = service.group().listAllGroupsWithInfo().collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
public reactor.core.publisher.Mono<EMPage<String>> listGroups(int limit, String cursor)
初次调用时,cursor
传 null
。之后的调用,cursor
传上次返回的值。
API使用示例:
EMPage<String> page = null;
try {
page = service.group().listGroups(10, null).block();
List<String> groupIds = page.getValues();
System.out.println("群组列表:" + groupIds);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
// ... do something with the groupIds ...
if (page != null) {
String cursor = page.getCursor();
// cursor == null indicates the end of the list
while (cursor != null) {
try {
page = service.group().listGroups(10, cursor).block();
System.out.println("群组列表:" + page.getValues());
// ... do something to the groupIds ...
cursor = page.getCursor();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
}
}
public reactor.core.publisher.Mono<EMPage<GroupResource>> listGroupsWithInfo(int limit, String cursor)
初次调用时,cursor
传 null
。之后的调用,cursor
传上次返回的值。
API使用示例:
EMPage<GroupResource> page = null;
try {
page = service.group().listGroupsWithInfo(10, null).block();
List<GroupResource> groupIds = page.getValues();
System.out.println("群组列表:" + groupIds);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
// ... do something with the groupIds ...
if (page != null) {
String cursor = page.getCursor();
// cursor == null indicates the end of the list
while (cursor != null) {
try {
page = service.group().listGroupsWithInfo(10, cursor).block();
System.out.println("群组列表:" + page.getValues());
// ... do something to the groupIds ...
cursor = page.getCursor();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
}
}
public reactor.core.publisher.Flux<String> listGroupsUserJoined(String username)
API使用示例:
EMService service;
try {
List<String> groups = service.group().listGroupsUserJoined("username").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- the usernameFlux
which emits EMGroup
on successful.public reactor.core.publisher.Flux<JoinGroupResource> listGroupsUserJoinedWithInfo(String username)
API使用示例:
EMService service;
try {
List<JoinGroupResource> groups = service.group().listGroupsUserJoined("username").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- the usernameFlux
which emits EMGroup
on successful.public reactor.core.publisher.Mono<List<JoinGroupResource>> listGroupsUserJoinedWithInfo(String username, int pageNum, int pageSize)
初次调用时,cursor
传 null
。之后的调用,cursor
传上次返回的值。
API使用示例:
try {
List<JoinGroupResource> groupResources = service.group().listGroupsUserJoinedWithInfo("username", 1, 10).block();
if (groupResources != null && groupResources.size() > 0) {
groupResources.forEach(groupResource -> {
System.out.println("groupId : " + groupResource.getGroupId());
System.out.println("groupName : " + groupResource.getGroupName());
});
}
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
username
- the usernamepageNum
- 当前页码pageSize
- 每页获取已加入的群组数量public reactor.core.publisher.Mono<EMGroup> getGroup(String groupId)
API使用示例:
EMService service;
try {
EMGroup group = service.group().getGroup("groupId").block();
String groupName = group.getName();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idpublic reactor.core.publisher.Mono<List<EMGroup>> getGroupList(List<String> groupIdList)
API使用示例:
EMService service;
try {
List<String> groupIdList = new ArrayList<>();
groupIdList.add("193100825821185");
groupIdList.add("193100825821186");
List<EMGroup> groupList = service.group().getGroupList(groupIdList).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupIdList
- 群id列表public reactor.core.publisher.Mono<Void> updateGroup(String groupId, Consumer<UpdateGroupRequest> customizer)
支持修改的参数见GroupSettingsUpdateRequest
API使用示例:
比如,更新群最大成员数:
EMService service;
try {
service.group().updateGroup("1", settings -> settings.maxMembers(100)).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idcustomizer
- 请求定制器UpdateGroupRequest
,
修改群详情public reactor.core.publisher.Mono<Void> updateGroupOwner(String groupId, String username)
EMForbiddenException
。
API使用示例:
EMService service;
try {
service.group().updateGroupOwner("groupId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idusername
- 新群主的用户名public reactor.core.publisher.Mono<String> getGroupAnnouncement(String groupId)
API使用示例:
EMService service;
try {
String groupAnnouncement = service.group().getGroupAnnouncement("groupId").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idpublic reactor.core.publisher.Mono<Void> updateGroupAnnouncement(String groupId, String announcement)
API使用示例:
EMService service;
try {
service.group().updateGroupAnnouncement("groupId", "announcement").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idannouncement
- 群公告public reactor.core.publisher.Flux<String> listAllGroupMembers(String groupId)
API使用示例:
EMService service;
try {
List<String> members = service.group().listAllGroupMembers("groupId").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idpublic reactor.core.publisher.Flux<String> listAllGroupMembers(String groupId, String sort)
API使用示例:
EMService service;
try {
List<String> members = service.group().listAllGroupMembers("groupId", "asc").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idsort
- 群成员排序方法 asc:根据加入顺序升序排序 desc:根据加入顺序降序排序public reactor.core.publisher.Flux<Map<String,String>> listAllGroupMembersIncludeOwner(String groupId, String sort)
API使用示例:
EMService service;
try {
List<Map<String, String>> members = service.group().listAllGroupMembersIncludeOwner("groupId", "asc").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idsort
- asc:根据加入顺序升序排序 desc:根据加入顺序降序排序public reactor.core.publisher.Mono<List<Map<String,String>>> listGroupMembersIncludeOwner(String groupId, int pageNum, int pageSize, String sort)
API使用示例:
EMService service;
EMPage<String> page = null;
try {
List<Map<String, String>> members = service.room().listGroupMembersIncludeOwner(groupId, 1, 10, asc).block();
System.out.println("群组成员列表:" + members);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组idpageNum
- 当前页码。默认从第 1 页开始获取pageSize
- 每页期望返回的群组成员数量。取值范围为[1,100]。默认为 10。sort
- asc:根据加入顺序升序排序 desc:根据加入顺序降序排序public reactor.core.publisher.Mono<EMPage<String>> listGroupMembers(String groupId, int limit, String cursor)
API使用示例:
首次调用时,cursor
传 null
。之后每次调用,cursor
传上次返回的值。
比如:
EMService service;
EMPage<String> page = null;
try {
page = service.group().listGroupMembers(groupId, 1, null).block();
List<String> members = page.getValues();
System.out.println("群组成员列表:" + members);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
// ... do something to the members ...
if (page != null) {
String cursor = page.getCursor();
while (cursor != null) {
try {
page = service.group().listGroupMembers(groupId, 1, cursor).block();
System.out.println("群组成员列表:" + page.getValues());
// ... do something to the members ...
cursor = page.getCursor();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
}
}
groupId
- 群idlimit
- 返回多少群成员idcursor
- 开始位置GroupMemberListResponse
,
获取群成员public reactor.core.publisher.Mono<EMPage<String>> listGroupMembers(String groupId, int limit, String cursor, String sort)
API使用示例:
首次调用时,cursor
传 null
。之后每次调用,cursor
传上次返回的值。
比如:
EMService service;
EMPage<String> page = null;
try {
page = service.group().listGroupMembers(groupId, 1, null, "asc").block();
List<String> members = page.getValues();
System.out.println("群组成员列表:" + members);
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
// ... do something to the members ...
if (page != null) {
String cursor = page.getCursor();
while (cursor != null) {
try {
page = service.group().listGroupMembers(groupId, 1, cursor, "asc").block();
System.out.println("群组成员列表:" + page.getValues());
// ... do something to the members ...
cursor = page.getCursor();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
}
}
groupId
- 群idlimit
- 返回多少群成员idcursor
- 开始位置sort
- 群成员排序方法 asc:根据加入顺序升序排序 desc:根据加入顺序降序排序GroupMemberListResponse
,
获取群成员public reactor.core.publisher.Mono<Void> addGroupMember(String groupId, String username)
API使用示例:
EMService service;
try {
service.group().addGroupMember("groupId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idusername
- 要添加的用户的用户名public reactor.core.publisher.Mono<Void> addGroupMembers(String groupId, List<String> usernames)
API使用示例:
EMService service;
try {
List<String> members = new ArrayList<>();
members.add("member1");
members.add("member2");
service.group().addGroupMembers("groupId", members).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idusernames
- 要添加的用户的用户名列表public reactor.core.publisher.Mono<Void> removeGroupMember(String groupId, String username)
API使用示例:
EMService service;
try {
service.group().removeGroupMember("groupId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idusername
- 要移除的用户的用户名public reactor.core.publisher.Mono<List<EMRemoveMember>> removeGroupMembers(String groupId, List<String> usernames)
API使用示例:
EMService service;
try {
List<String> members = new ArrayList<>();
members.add("member1");
members.add("member2");
List<EMRemoveMember> removeMembers = service.group().removeGroupMembers("groupId", members).block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idusernames
- 要移除的用户的用户名列表public reactor.core.publisher.Flux<String> listGroupAdmins(String groupId)
API使用示例:
EMService service;
try {
List<String> admins = service.group().listGroupAdmins("groupId").collectList().block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idpublic reactor.core.publisher.Mono<Void> addGroupAdmin(String groupId, String username)
API使用示例:
EMService service;
try {
service.group().addGroupAdmin("groupId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idusername
- 被升级的群成员的用户名public reactor.core.publisher.Mono<Void> removeGroupAdmin(String groupId, String username)
API使用示例:
EMService service;
try {
service.group().removeGroupAdmin("groupId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idusername
- 被降级的群管理员的用户名public reactor.core.publisher.Mono<Void> assignGroup(String groupId, String newOwner)
API使用示例:
EMService service;
try {
service.group().assignGroup("groupId", "newOwner").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群idnewOwner
- 被转让群组的用户名public reactor.core.publisher.Mono<Boolean> userIsJoined(String groupId, String username)
API使用示例:
EMService service;
try {
Boolean result = service.group().userIsJoined("groupId", "username").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组idusername
- 需要查看的用户名public reactor.core.publisher.Mono<Boolean> disableGroup(String groupId)
封禁指定的群组。例如,群成员经常在群中发送违规消息,可以调用该 API 对该群进行封禁。 群组被封禁后,群中任何成员均无法在群组以及该群组下的子区中发送和接收消息,也无法进行群组和子区管理操作。
API使用示例:
EMService service;
try {
Boolean result = service.group().disableGroup("groupId").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组idpublic reactor.core.publisher.Mono<Boolean> enableGroup(String groupId)
解除对指定群组的封禁。群组解禁后,群成员可以在该群组以及该群组下的子区中发送和接收消息并进行群组和子区管理相关操作。
API使用示例:
EMService service;
try {
Boolean result = service.group().enableGroup("groupId").block();
} catch (EMException e) {
e.getErrorCode();
e.getMessage();
}
groupId
- 群组idCopyright © 2024. All rights reserved.