群管理

群主与管理员可修改群资料、转让群主、设置管理员与成员禁言。

平台调用风格

双语言同契约:Swift 用 async -> RcResult<T>(错误码在 RcResult.code,返回 null 的 op 用 RcResult<Void>);Objective-C 用 - (void)opWithParam:... completion:(void (^)(RcResult *))completion,回调在主线程投递。

接口一览​

操作语义传输返回
updateGroupName修改群名(群主/管理员)。REST(客户端)Group
updateGroupNotice设置群公告(群主/管理员,<=500 字,空串清除)。REST(客户端)Group
transferGroupOwner转让群主(新群主须为成员)。REST(客户端)Group
addGroupAdmin设置管理员(群主,幂等)。REST(客户端)Group
removeGroupAdmin取消管理员(群主)。REST(客户端)Group
muteGroupMember禁言/解禁(群主/管理员;不能禁言群主;管理员不能禁言管理员)。REST(客户端){groupId:string,userId:string,mutedUntil:uint64,group:Group}

本页 6 个操作,其中 6 个在本平台绑定中声明了方法签名。

跨端方法名​

操作AndroidWebElectronmacOSFlutterNative (C ABI)iOS
updateGroupNameupdateGroupNameupdateGroupNameupdateGroupNameupdateGroupNameupdateGroupName—func
updateGroupNoticeupdateGroupNoticeupdateGroupNoticeupdateGroupNoticeupdateGroupNoticeupdateGroupNotice—func
transferGroupOwnertransferGroupOwnertransferGroupOwnertransferGroupOwnertransferGroupOwnertransferGroupOwner—func
addGroupAdminaddGroupAdminaddGroupAdminaddGroupAdminaddGroupAdminaddGroupAdmin—func
removeGroupAdminremoveGroupAdminremoveGroupAdminremoveGroupAdminremoveGroupAdminremoveGroupAdmin—func
muteGroupMembermuteGroupMembermuteGroupMembermuteGroupMembermuteGroupMembermuteGroupMember—func

方法名在 GA 平台之间保持一致(规则 A);Native C ABI 只覆盖部分操作,其余操作以 — 标注。

updateGroupName​

修改群名(群主/管理员)。

func updateGroupName(groupId: String, name: String) async -> RcResult<IMPGroup>
REST(客户端)since 1.0.0
参数
参数类型说明
groupIdstring必填;群组 ID
namestring必填;名称(群名 / 聊天室名 / 文件名)
返回

Group 群资料

示例(Swift / Objective-C)​

let res = await client.updateGroupName(groupId: "g_1001", name: "产品群")
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client updateGroupNameWithGroupId:@"g_1001" name:@"产品群" completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
错误码
错误码名称分类HTTP可重试说明
1001INVALID_PARAMETER客户端 / 参数 / 权限400否参数错误
1003FORBIDDEN客户端 / 参数 / 权限403否无权限
1005GROUP_NOT_FOUND客户端 / 参数 / 权限404否群组不存在

updateGroupNotice​

设置群公告(群主/管理员,<=500 字,空串清除)。

func updateGroupNotice(groupId: String, notice: String) async -> RcResult<IMPGroup>
REST(客户端)since 1.0.0
参数
参数类型说明
groupIdstring必填;群组 ID
noticestring必填;群公告文本(<=500 字,空串清除)
返回

Group 群资料

示例(Swift / Objective-C)​

let res = await client.updateGroupNotice(groupId: "g_1001", notice: "本周五 20:00 全员复盘")
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client updateGroupNoticeWithGroupId:@"g_1001" notice:@"本周五 20:00 全员复盘" completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
错误码
错误码名称分类HTTP可重试说明
1001INVALID_PARAMETER客户端 / 参数 / 权限400否参数错误
1003FORBIDDEN客户端 / 参数 / 权限403否无权限
1005GROUP_NOT_FOUND客户端 / 参数 / 权限404否群组不存在

transferGroupOwner​

转让群主(新群主须为成员)。

func transferGroupOwner(groupId: String, newOwner: String) async -> RcResult<IMPGroup>
REST(客户端)since 1.0.0
参数
参数类型说明
groupIdstring必填;群组 ID
newOwnerstring必填;新群主用户 ID(必须是群成员)
返回

Group 群资料

示例(Swift / Objective-C)​

let res = await client.transferGroupOwner(groupId: "g_1001", newOwner: "user2")
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client transferGroupOwnerWithGroupId:@"g_1001" newOwner:@"user2" completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
错误码
错误码名称分类HTTP可重试说明
1001INVALID_PARAMETER客户端 / 参数 / 权限400否参数错误
1003FORBIDDEN客户端 / 参数 / 权限403否无权限
1004USER_NOT_FOUND客户端 / 参数 / 权限404否用户不存在
1005GROUP_NOT_FOUND客户端 / 参数 / 权限404否群组不存在

addGroupAdmin​

设置管理员(群主,幂等)。

func addGroupAdmin(groupId: String, userId: String) async -> RcResult<IMPGroup>
REST(客户端)幂等since 1.0.0
参数
参数类型说明
groupIdstring必填;群组 ID
userIdstring必填;用户 ID
返回

Group 群资料

示例(Swift / Objective-C)​

let res = await client.addGroupAdmin(groupId: "g_1001", userId: "user2")
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client addGroupAdminWithGroupId:@"g_1001" userId:@"user2" completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
错误码
错误码名称分类HTTP可重试说明
1001INVALID_PARAMETER客户端 / 参数 / 权限400否参数错误
1003FORBIDDEN客户端 / 参数 / 权限403否无权限
1004USER_NOT_FOUND客户端 / 参数 / 权限404否用户不存在
1005GROUP_NOT_FOUND客户端 / 参数 / 权限404否群组不存在

removeGroupAdmin​

取消管理员(群主)。

func removeGroupAdmin(groupId: String, userId: String) async -> RcResult<IMPGroup>
REST(客户端)幂等since 1.0.0
参数
参数类型说明
groupIdstring必填;群组 ID
userIdstring必填;用户 ID
返回

Group 群资料

示例(Swift / Objective-C)​

let res = await client.removeGroupAdmin(groupId: "g_1001", userId: "user2")
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client removeGroupAdminWithGroupId:@"g_1001" userId:@"user2" completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
错误码
错误码名称分类HTTP可重试说明
1001INVALID_PARAMETER客户端 / 参数 / 权限400否参数错误
1003FORBIDDEN客户端 / 参数 / 权限403否无权限
1005GROUP_NOT_FOUND客户端 / 参数 / 权限404否群组不存在

muteGroupMember​

禁言/解禁(群主/管理员;不能禁言群主;管理员不能禁言管理员)。

func muteGroupMember(groupId: String, userId: String, mutedUntil: UInt64) async -> RcResult<IMPMuteGroupMemberResult>
REST(客户端)since 1.0.0
参数
参数类型说明
groupIdstring必填;群组 ID
userIdstring必填;用户 ID
mutedUntiluint64必填;禁言到期时间(epoch 毫秒;0 表示解除禁言)
返回

{groupId:string,userId:string,mutedUntil:uint64,group:Group} 成功返回的数据;失败时按错误码处理

示例(Swift / Objective-C)​

let res = await client.muteGroupMember(groupId: "g_1001", userId: "user2", mutedUntil: 0)
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client muteGroupMemberWithGroupId:@"g_1001" userId:@"user2" mutedUntil:0 completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
错误码
错误码名称分类HTTP可重试说明
1001INVALID_PARAMETER客户端 / 参数 / 权限400否参数错误
1003FORBIDDEN客户端 / 参数 / 权限403否无权限
1004USER_NOT_FOUND客户端 / 参数 / 权限404否用户不存在
1005GROUP_NOT_FOUND客户端 / 参数 / 权限404否群组不存在
1006NOT_GROUP_MEMBER客户端 / 参数 / 权限403否未加入群组

相关文档​