群组相关

更新时间: 2024/10/18 10:05:33

网易云信即时通讯 SDK(NetEase IM SDK,以下简称 NIM SDK)提供了高级群和超大群两种形式的群组功能,支持用户创建、加入、退出、转让、修改、查询、解散群组,拥有完善的管理功能。

本文介绍群组管理相关 API。更多群组相关功能请参考 群组概述

API 概览

群组监听

API 说明 起始版本
add 注册群组相关监听器 v10.3.0
cancel 取消注册群组相关监听器 v10.3.0

群组操作

API 说明 起始版本
createTeam 创建一个群组 v10.3.0
updateTeamInfo 修改群组信息 v10.3.0
leaveTeam 退出群组 v10.3.0
getTeamInfo 获取群组信息 v10.3.0
getTeamInfoByIds 根据群组 ID 批量获取群组信息 v10.3.0
dismissTeam 解散群组 v10.3.0
inviteMember 邀请成员加入群组 v10.3.0
acceptInvitation 接受入群邀请 v10.3.0
rejectInvitation 拒绝入群邀请 v10.3.0
kickMember 踢出群成员 v10.3.0
applyJoinTeam 申请加入群组 v10.3.0
acceptJoinApplication 同意入群申请 v10.3.0
rejectJoinApplication 拒绝入群申请 v10.3.0
updateTeamMemberRole 修改群成员角色 v10.3.0
transferTeamOwner 转让群主身份 v10.3.0
updateSelfTeamMemberInfo 修改自己的群成员信息 v10.3.0
updateTeamMemberNick 修改群成员昵称 v10.3.0
setTeamChatBannedMode 设置群组禁言模式 v10.3.0
setTeamMemberChatBannedStatus 设置群成员聊天禁言状态 v10.3.0
getJoinedTeamList 获取当前已经加入的群组列表 v10.3.0
getJoinedTeamCount 获取当前已经加入的群组数量 v10.3.0
getTeamMemberList 分页获取群组成员列表 v10.3.0
getTeamMemberListByIds 根据账号批量获取群组成员列表 v10.3.0
getTeamMemberInvitor 根据账号获取群组成员邀请人 v10.3.0
getTeamJoinActionInfoList 获取入群操作相关信息列表 v10.3.0
searchTeamByKeyword 根据关键字搜索群信息(包括高级群和超大群) v10.3.0
searchTeamMembers 根据关键字搜索群成员(包括高级群和超大群) v10.3.0

接口类

TeamService 类提供群组相关接口,包括注册群组监听,创建、修改、退出、解散、加入群组、获取群组相关信息等接口。

add

接口描述

注册群组相关监听器。

注册成功后,当事件发生时,SDK 会返回对应的回调。

  • 建议在初始化后调用该方法。
  • 全局只需注册一次。
  • 该方法为同步。

回调事件

  • onSyncStarted:群组信息同步开始回调,包括群组信息、群成员信息。
  • onSyncFinished:群组信息同步结束回调。如果群组信息同步已开始,建议在同步结束后进行群组相关操作(例如查询群组列表),否则可能导致数据不完整。
  • onSyncFailed:群组信息同步失败回调,返回 NIMError 错误码。收到该回调后进行群组相关操作可能导致数据不完整。
  • onTeamCreated:群组成功创建回调,返回 NIMTeam。当本地端或多端同步创建群组成功时会触发该回调。
  • onTeamDismissed:群组解散回调,返回 NIMTeam。当本地端或多端同步解散群组成功时会触发该回调。群组内所有成员均会收到该回调。
  • onTeamJoined:加入群组回调,返回 NIMTeam。当本地端或多端同步加入群组时会触发该回调。
  • onTeamLeft:离开群组回调,返回 NIMTeam。当本地端或多端主动离开群组或被踢出群组时会触发该回调。
  • onTeamInfoUpdated:群组信息更新回调,返回 NIMTeam。群组内所有成员均会收到该回调。
  • onTeamMemberJoined:成员加入群组回调,返回 NIMTeamMember。群组内所有成员均会收到该回调。
  • onTeamMemberKicked:群成员被踢出群组回调,返回 NIMTeamMember 列表。群组内所有成员均会收到该回调。
  • onTeamMemberLeft:群成员离开群组回调,返回 NIMTeamMember 列表。群组内所有成员均会收到该回调。
  • onTeamMemberInfoUpdated:群成员信息变更回调,返回 NIMTeamMember 列表。群组内所有成员均会收到该回调。
  • onReceiveTeamJoinActionInfo:收到入群操作信息回调,返回 NIMTeamJoinActionInfo

示例代码

dartsubsriptions.add(NimCore.instance.teamService.onSyncStarted.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onSyncFinished.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onSyncFailed.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamCreated.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamDismissed.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamJoined.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamLeft.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamInfoUpdated.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamMemberJoined.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamMemberKicked.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamMemberLeft.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onTeamMemberInfoUpdated.listen((e) {
      //do something
    }));
    subsriptions.add(NimCore.instance.teamService.onReceiveTeamJoinActionInfo.listen((e) {
      //do something
    }));

cancel

接口描述

取消注册群组相关监听。

该方法为同步。

示例代码

dartsubsriptions.forEach((subsription) {
      subsription.cancel();
    });

createTeam

接口描述

创建一个群组。支持创建高级群和超大群,二者区别请参考 群组概述

本地端或多端同步创建成功后,SDK 会返回创建成功回调 onTeamCreated,并同步缓存和数据库。

客户端 SDK 不支持创建 2000 人以上的超大群,请调用服务端 API 创建群组

参数说明

dartFuture<NIMResult<NIMCreateTeamResult>> createTeam(
    NIMCreateTeamParams createTeamParams,
    List<String>? inviteeAccountIds,
    String? postscript,
    NIMAntispamConfig? antispamConfig) async {
  return _platform.createTeam(
      createTeamParams, inviteeAccountIds, postscript, antispamConfig);
}
参数名称 类型 是否必填 说明
createTeamParams NIMCreateTeamParams 群组创建配置参数。
inviteeAccountIds List<string> 被邀请加入群组的成员列表,单次调用不超过 50 人。
postscript String 邀请入群附言。
antispamConfig NIMAntispamConfig 易盾反垃圾相关配置。使用网易云信安全通无需配置该参数。

示例代码

dartawait NimCore.instance.teamService.createTeam(createTeamParams, inviteeAccountIds, postscript, antispamConfig);

返回值

NIMResult<NIMCreateTeamResult>:群组创建结果

相关回调

onTeamCreated:群组成功创建回调

leaveTeam

接口描述

退出指定群组。

本地端或多端同步退出群组成功后:

  • 本端 SDK 会触发退出群组回调 onTeamLeft
  • 群组内所有成员会收到通知消息(通知消息类型为 NIMMessageNotificationType.teamLeave )以及 onTeamMemberLeft 回调。

参数说明

dartFuture<NIMResult<void>> leaveTeam(String teamId, NIMTeamType teamType) async {
  return _platform.leaveTeam(teamId, teamType);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。

示例代码

dartawait NimCore.instance.teamService.leaveTeam(teamId, teamType);

返回值

NIMResult<void>

相关回调

  • onTeamLeft:离开群组回调
  • onTeamMemberLeft:群成员离开群组回调

updateTeamInfo

接口描述

更新指定群组信息。

本地端或多端同步更新成功后,群组内所有成员会收到群组信息变更回调 onTeamInfoUpdated,以及群组信息更新的通知消息,通知消息类型为 NIMMessageNotificationType.teamUpdateTInfo

更新前请确保该群组已存在。

参数说明

dartFuture<NIMResult<void>> updateTeamInfo(
    String teamId,
    NIMTeamType teamType,
    NIMUpdateTeamInfoParams updateTeamInfoParams,
    NIMAntispamConfig? antispamConfig) async {
  return _platform.updateTeamInfo(
      teamId, teamType, updateTeamInfoParams, antispamConfig);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。
updateTeamInfoParams NIMUpdateTeamInfoParams 群组信息更新配置参数。
antispamConfig NIMAntispamConfig 易盾反垃圾相关配置。使用网易云信安全通无需配置该参数。

示例代码

dartawait NimCore.instance.teamService.updateTeamInfo(teamId, teamType, updateTeamInfoParams, antispamConfig);

返回值

NIMResult<void>

相关回调

onTeamInfoUpdated:群组信息更新回调

getTeamInfo

接口描述

获取指定的单个群组信息。

  • 获取前请确保指定的群组存在。
  • 群组数据同步(onSyncFinished)完成前,可能获取不到完整数据。

参数说明

dartFuture<NIMResult<NIMTeam>> getTeamInfo(
    String teamId, NIMTeamType teamType) async {
  return _platform.getTeamInfo(teamId, teamType);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。

示例代码

dartawait NimCore.instance.teamService.getTeamInfo(teamId, teamType);

返回值

NIMResult<NIMTeam>:群组对象

相关回调

getTeamInfoByIds

接口描述

根据群组 ID 批量获取最多十个群组的信息列表(包含已退出或已被解散的群组)。

SDK 获取策略如下:

查询引用消息.drawio.png

群组数据同步(onSyncFinished)完成前,可能获取不到完整数据。

参数说明

dartFuture<NIMResult<List<NIMTeam>>> getTeamInfoByIds(
    List<String> teamIds, NIMTeamType teamType) async {
  return _platform.getTeamInfoByIds(teamIds, teamType);
}
参数名称 类型 是否必填 说明
teamIds List<String> 群组 ID 列表,不能超过十个群组 ID。该参数不可为空,否则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。

示例代码

dartawait NimCore.instance.teamService.getTeamInfoByIds(teamIds, teamType);

返回值

NIMResult<List<NIMTeam>>:群组对象列表

相关回调

dismissTeam

接口描述

解散指定群组。

本地端或多端同步解散群组成功后:

  • 本地端 SDK 会返回删除成功回调 onTeamDismissed
  • 群组内所有成员会收到通知消息,通知消息类型为 NIMMessageNotificationType.teamDismiss

仅允许群主调用该接口,否则返回错误码 109427。

参数说明

dartFuture<NIMResult<void>> dismissTeam(
    String teamId, NIMTeamType teamType) async {
  return _platform.dismissTeam(teamId, teamType);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。

示例代码

dartawait NimCore.instance.teamService.dismissTeam(teamId, teamType);

返回值

NIMResult<void>

相关回调

onTeamDismissed:群组解散回调

inviteMember

接口描述

邀请用户加入群组。

本地端或多端同步邀请成功后,群组内其他成员收到一条通知类消息,类型为 NIMMessageNotificationType.teamInvite。根据创建群组时设置的被邀请方同意模式,有以下回调场景:

  • NIMTeam.agreeMode 为 0:即需要被邀请方同意后加入群,则被邀请方收到邀请入群回调 onReceiveTeamJoinActionInfo
  • NIMTeam.agreeMode 为 1:即不需要被邀请方同意,则被邀请方直接加入群组,此时被邀请方收到 onTeamJoined 回调,其他群成员收到 onTeamMemberJoined 回调。

参数说明

dartFuture<NIMResult<List<String>>> inviteMember(
    String teamId,
    NIMTeamType teamType,
    List<String> inviteeAccountIds,
    String? postscript) async {
  return _platform.inviteMember(
      teamId, teamType, inviteeAccountIds, postscript);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。
inviteeAccountIds List<String> 被邀请入群的用户账号列表。不可为空,否则返回 191004 参数错误。
postscript String 邀请入群附言。

示例代码

dartawait NimCore.instance.teamService.inviteMember(teamId, teamType, inviteeAccountIds, postscript);

返回值

NIMResult<List<String>>:邀请失败的用户账号(accountId)列表

相关回调

  • onReceiveTeamJoinActionInfo:收到入群操作信息回调
  • onTeamJoined:加入群组回调
  • onTeamMemberJoined:成员加入群组回调

acceptInvitation

接口描述

接受入群邀请。

本地端或多端同步接受入群邀请成功后:

  • 本地端收到加入群组成功回调 onTeamJoined
  • 群组内其他成员收到一条通知类消息,类型为 NIMMessageNotificationType.teamInviteAccept。收到其他用户加入群组回调 onTeamMemberJoined

参数说明

dartFuture<NIMResult<NIMTeam>> acceptInvitation(
    NIMTeamJoinActionInfo invitationInfo) async {
  return _platform.acceptInvitation(invitationInfo);
}
参数名称 类型 是否必填 说明
invitationInfo NIMTeamJoinActionInfo 邀请入群信息。其中 actionType 必须为 NIMTeamJoinActionType.joinActionTypeInvitation,否则返回 191004 参数错误。

示例代码

dartawait NimCore.instance.teamService.acceptInvitation(invitationInfo);

返回值

NIMResult<NIMTeam>:群组对象

相关回调

  • onTeamJoined:加入群组回调
  • onTeamMemberJoined:成员加入群组回调

rejectInvitation

接口描述

拒绝入群邀请。

本地端或多端拒绝入群邀请成功后,群主和群管理员收到 onReceiveTeamJoinActionInfo 回调,NIMTeamJoinActionTypejoinActionTypeRejectInvitation

参数说明

dartFuture<NIMResult<void>> rejectInvitation(
    NIMTeamJoinActionInfo invitationInfo, String? postscript) async {
  return _platform.rejectInvitation(invitationInfo, postscript);
}
参数名称 类型 是否必填 说明
invitationInfo NIMTeamJoinActionInfo 邀请入群信息。其中 actionType 必须为 joinActionTypeRejectInvitation,否则返回 191004 参数错误。
postscript String 拒绝邀请附言。

示例代码

dartawait NimCore.instance.teamService.rejectInvitation(invitationInfo, postscript);

返回值

NIMResult<void>

相关回调

onReceiveTeamJoinActionInfo:收到入群操作信息回调

kickMember

接口描述

批量将群组成员踢出群组。

本地端或多端同步踢出群组成员成功后:

  • 被踢方收到离开群组回调 onTeamLeft
  • 群组内所有成员收到一条通知类消息,类型为 NIMMessageNotificationType.teamKick。收到群成员被踢回调 onTeamMemberKicked
  • 只有群主和管理员才能将成员踢出群组。
  • 管理员不能踢群主和其他管理员。

参数说明

dartFuture<NIMResult<void>> kickMember(String teamId, NIMTeamType teamType,
    List<String>? memberAccountIds) async {
  return _platform.kickMember(teamId, teamType, memberAccountIds);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。
memberAccountIds List<String> 踢出群组的成员账号(accountId)列表,不可为空,否则返回 191004 参数错误。

示例代码

dartawait NimCore.instance.teamService.kickMember(teamId, teamType, memberAccountIds);

返回值

NIMResult<void>

相关回调

  • onTeamLeft:离开群组回调
  • onTeamMemberKicked:群成员被踢出群组回调

applyJoinTeam

接口描述

申请加入群组。

本地端或多端同步申请加入群组成功后,根据创建群组时设置的入群验证模式,有以下回调场景:

  • NIMTeam.joinMode 为 0:即无需验证直接加入群组,此时本端收到加入群组回调 onTeamJoined,其他群成员收到群成员入群回调 onTeamMemberJoined 和群信息更新回调 onTeamInfoUpdated
  • NIMTeam.joinMode 为 1:即需要群主或管理员验证同意后加入群,则群主和管理员收到 onReceiveTeamJoinActionInfo 回调,NIMTeamJoinActionTypejoinActionTypeApplication
  • NIMTeam.joinMode 为 2:即私有群,该模式不支持入群申请,仅能通过邀请方式入群,此时 SDK 不会触发任何回调。

参数说明

dartFuture<NIMResult<NIMTeam>> applyJoinTeam(
    String teamId, NIMTeamType teamType, String? postscript) async {
  return _platform.applyJoinTeam(teamId, teamType, postscript);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。
postscript String 申请入群附言。

示例代码

dartawait NimCore.instance.teamService.applyJoinTeam(teamId, teamType, postscript);

返回值

NIMResult<NIMTeam>:群组对象

相关回调

  • onTeamJoined:加入群组回调
  • onTeamMemberJoined:成员加入群组回调
  • onTeamInfoUpdated:群组信息更新回调
  • onReceiveTeamJoinActionInfo:收到入群操作信息回调

acceptJoinApplication

接口描述

同意入群申请。

本地端或多端同步同意入群申请成功后:

  • 群主和群管理员收到一条通知类消息,类型为 NIMMessageNotificationType.teamApplyPass
  • 申请方加入群组,收到加入群组成功回调 onTeamJoined。群组内所有成员收到群成员入群回调 onTeamMemberJoined 和群信息更新回调 onTeamInfoUpdated

仅允许群主或管理员调用该接口,否则返回错误码 109432。

参数说明

dartFuture<NIMResult<void>> acceptJoinApplication(
    NIMTeamJoinActionInfo applicationInfo) async {
  return _platform.acceptJoinApplication(applicationInfo);
}
参数名称 类型 是否必填 说明
applicationInfo NIMTeamJoinActionInfo 申请入群信息。其中 actionType 必须为 joinActionTypeApplication ,否则返回 191004 参数错误。

示例代码

dartawait NimCore.instance.teamService.acceptJoinApplication(applicationInfo);

返回值

NIMResult<void>

相关回调

  • onTeamJoined:加入群组回调
  • onTeamMemberJoined:成员加入群组回调
  • onTeamInfoUpdated:群组信息更新回调

rejectJoinApplication

接口描述

拒绝入群申请。

本地端或多端同步拒绝入群申请成功后:

入群申请方收到 onReceiveTeamJoinActionInfo 回调,NIMTeamJoinActionTypejoinActionTypeRejectApplication

仅允许群主或管理员调用该接口,否则返回错误码 109432。

参数说明

dartFuture<NIMResult<void>> rejectJoinApplication(
    NIMTeamJoinActionInfo applicationInfo, String? postscript) async {
  return _platform.rejectJoinApplication(applicationInfo, postscript);
}
参数名称 类型 是否必填 说明
applicationInfo NIMTeamJoinActionInfo 申请入群信息。其中 actionType 必须为 joinActionTypeApplication,否则返回 191004 参数错误。
postscript String 拒绝入群申请附言。

示例代码

dartawait NimCore.instance.teamService.rejectJoinApplication(applicationInfo, postscript);

返回值

NIMResult<void>

相关回调

onReceiveTeamJoinActionInfo:收到入群操作信息回调

updateTeamMemberRole

接口描述

批量更新群成员角色类型。

本地端或多端同步更新群成员角色类型成功后:

  • 群组内所有成员收到群成员信息变更回调 onTeamMemberInfoUpdated
  • 群主添加管理员后(blockedtrue),所有群成员会收到群组通知消息,通知消息类型为 NIMMessageNotificationType.teamAddManager。群主移除管理员后(修改角色类型为普通成员),所有群成员收到群组通知消息类型为 NIMMessageNotificationType.teamRemoveManager

仅允许群主调用该接口,否则返回错误码 109427。

参数说明

dartFuture<NIMResult<void>> updateTeamMemberRole(
    String teamId,
    NIMTeamType teamType,
    List<String> memberAccountIds,
    NIMTeamMemberRole memberRole) async {
  return _platform.updateTeamMemberRole(
      teamId, teamType, memberAccountIds, memberRole);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。
memberAccountIds List<String> 群成员账号(accountId)列表,不可为空,否则返回 191004 参数错误。
memberRole NIMTeamMemberRole 群成员角色类型。仅支持设置为群普通成员或群管理员,否则返回 191004 参数错误。

示例代码

dartawait NimCore.instance.teamService.updateTeamMemberRole(teamId, teamType, memberAccountIds, memberRole);

返回值

NIMResult<void>

相关回调

onTeamMemberInfoUpdated:群成员信息变更回调

transferTeamOwner

接口描述

转让群主身份。

本地端或多端同步转让群主身份成功后:

  • 群组内所有成员收到群组通知消息,通知消息类型为 NIMMessageNotificationType.teamOwnerTransfer。以及群信息更新回调 onTeamInfoUpdated 和群成员信息变更回调 onTeamMemberInfoUpdated
  • 若调用该方法时设置 leave 参数为 true,即转让群主身份后同时退出该群:
    • 操作方:退出群组,收到退出群组回调 onTeamLeft
    • 群组内所有成员:
      • 收到成员退出群组回调 onTeamMemberLeft
      • 收到群组通知消息,通知消息类型为 NIMMessageNotificationType.teamLeave
  • 仅允许群主调用该接口,否则返回错误码 109427。
  • 不允许转让给自己。

参数说明

dartFuture<NIMResult<void>> transferTeamOwner(
    String teamId, NIMTeamType teamType, String accountId, bool leave) async {
  return _platform.transferTeamOwner(teamId, teamType, accountId, leave);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。
accountId String 新群主账号,如果为空、不合法、不存在,或与操作者账号相同,则返回 191004 参数错误。
leave bool 转让群主身份后,是否同时退出该群,默认为 false。
  • true:转让群主身份后,同时退出该群。
  • false:转让群主身份后留在群中,成员角色从群主转变为普通成员。
  • 示例代码

    dartawait NimCore.instance.teamService.transferTeamOwner(teamId, teamType, accountId, leave);
    

    返回值

    NIMResult<void>

    相关回调

    • onTeamInfoUpdated:群组信息更新回调
    • onTeamMemberInfoUpdated:群成员信息变更回调
    • onTeamLeft:离开群组回调
    • onTeamMemberLeft:群成员离开群组回调

    updateSelfTeamMemberInfo

    接口描述

    更新本人群成员信息。

    本地端或多端同步更新本人群成员信息成功后,群组内所有成员收到群成员信息变更回调 onTeamMemberInfoUpdated

    参数说明

    dartFuture<NIMResult<void>> updateSelfTeamMemberInfo(
        String teamId,
        NIMTeamType teamType,
        NIMUpdateSelfMemberInfoParams memberInfoParams) async {
      return _platform.updateSelfTeamMemberInfo(
          teamId, teamType, memberInfoParams);
    }
    
    参数名称 类型 是否必填 说明
    teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType NIMTeamType 群组类型,包括高级群和超大群。
    memberInfoParams NIMUpdateSelfMemberInfoParams 本人群成员信息配置,包含群成员昵称及服务端扩展字段。

    示例代码

    dartawait NimCore.instance.teamService.updateSelfTeamMemberInfo(teamId, teamType, memberInfoParams);
    

    返回值

    NIMResult<void>

    相关回调

    onTeamMemberInfoUpdated:群成员信息变更回调

    updateTeamMemberNick

    接口描述

    更新群成员昵称。

    本地端或多端同步更新成功后,群组内所有成员会收到群成员信息变更回调 onTeamMemberInfoUpdated

    仅允许群主和管理员调用该接口,否则返回错误码 109432。

    参数说明

    dartFuture<NIMResult<void>> updateTeamMemberNick(String teamId,
        NIMTeamType teamType, String accountId, String teamNick) async {
      return _platform.updateTeamMemberNick(
          teamId, teamType, accountId, teamNick);
    }
    
    参数名称 类型 是否必填 说明
    teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType NIMTeamType 群组类型,包括高级群和超大群。
    accountId String 群成员账号,如果为空、不合法、不存在,则返回 191004 参数错误。
    teamNick String 群成员新昵称,可以设置为 "",但不可设置 null,否则返回 191004 参数错误。

    示例代码

    dartawait NimCore.instance.teamService.updateTeamMemberNick(teamId, teamType, accountId, teamNick);
    

    返回值

    NIMResult<void>

    相关回调

    onTeamMemberInfoUpdated:群成员信息变更回调

    setTeamChatBannedMode

    接口描述

    设置群组禁言模式。

    本地端或多端同步设置成功后,群组内所有成员会收到群组信息变更回调 onTeamInfoUpdate 以及群信息变更的通知类消息,消息类型为 NIMMessageNotificationType.teamUpdateTInfo

    仅允许群主和管理员调用该接口,否则返回错误码 109432。

    参数说明

    dartFuture<NIMResult<void>> setTeamChatBannedMode(String teamId,
        NIMTeamType teamType, NIMTeamChatBannedMode chatBannedMode) async {
      return _platform.setTeamChatBannedMode(teamId, teamType, chatBannedMode);
    }
    
    参数名称 类型 是否必填 说明
    teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType NIMTeamType 群组类型,包括高级群和超大群。
    chatBannedMode NIMTeamChatBannedMode 群组禁言模式。
  • 仅允许设置为不禁言和普通成员全员禁言,否则返回 191004 参数错误。
  • 如需全员禁言(包含群主和群管理员),请调用服务端 API 更新群组信息
  • 示例代码

    dartawait NimCore.instance.teamService.setTeamChatBannedMode(teamId, teamType, chatBannedMode);
    

    返回值

    NIMResult<void>

    相关回调

    onTeamInfoUpdate:群组信息更新回调

    setTeamMemberChatBannedStatus

    接口描述

    设置群组成员禁言状态。

    本地端或多端同步设置成功后,群组内所有成员会收到群成员信息变更回调 onTeamMemberInfoUpdated 以及群成员禁言的通知类消息,消息类型为 NIMMessageNotificationType.teamBannedTeamMember

    仅允许群主和管理员调用该接口,否则返回错误码 109432。

    参数说明

    dartFuture<NIMResult<void>> setTeamMemberChatBannedStatus(String teamId,
        NIMTeamType teamType, String accountId, bool chatBanned) async {
      return _platform.setTeamMemberChatBannedStatus(
          teamId, teamType, accountId, chatBanned);
    }
    
    参数名称 类型 是否必填 说明
    teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType NIMTeamType 群组类型,包括高级群和超大群。
    accountId String 群组成员账号,如果为空、不合法、不存在,则返回 191004 参数错误。
    chatBanned bool 群组成员是否被禁言。
  • true:被禁言
  • false:取消禁言。
  • 示例代码

    dartawait NimCore.instance.teamService.setTeamMemberChatBannedStatus(teamId, teamType, accountId, chatBanned);
    

    返回值

    NIMResult<void>

    相关回调

    onTeamMemberInfoUpdated:群成员信息变更回调

    getJoinedTeamList

    接口描述

    按照群组类型获取已经加入的群组列表。返回群组列表按照创建时间的升序排序。

    • 获取前请确保指定的群组存在。
    • 群组数据同步(onSyncFinished)完成前,可能获取不到完整数据。

    参数说明

    dartFuture<NIMResult<List<NIMTeam>>> getJoinedTeamList(
        List<NIMTeamType> teamTypes) async {
      return _platform.getJoinedTeamList(teamTypes);
    }
    
    参数名称 类型 是否必填 说明
    teamTypes List<NIMTeamType> 群组类型列表。不可设置为 null,设置为空则表示获取所有类型的群组。

    示例代码

    dartawait NimCore.instance.teamService.getJoinedTeamList(teamTypes);
    

    返回值

    NIMResult<List<NIMTeam>>:群组列表

    相关回调

    getJoinedTeamCount

    接口描述

    按照群组类型获取已经加入的群组数量。

    • 该方法为同步。
    • 群组数据同步(onSyncFinished)完成前,可能获取不到完整数据。

    参数说明

    dartFuture<NIMResult<int>> getJoinedTeamCount(List<NIMTeamType> teamTypes) async {
      return _platform.getJoinedTeamCount(teamTypes);
    }
    
    参数名称 类型 是否必填 说明
    teamTypes List<NIMTeamType> 群组类型列表。不可设置为 null,设置为空则表示获取所有类型的群组数量。

    示例代码

    dartawait NimCore.instance.teamService.getJoinedTeamCount(teamTypes);
    

    返回值

    NIMResult<int>:加入的群组数量

    相关回调

    getTeamMemberList

    接口描述

    分页获取群组成员列表。返回成员列表按照加入群组的时间戳(NIMTeamMember.joinTime)排序。

    • 获取前请确保指定的群组存在。
    • 群组数据同步(onSyncFinished)完成前,可能获取不到完整数据。

    参数说明

    dartFuture<NIMResult<NIMTeamMemberListResult>> getTeamMemberList(String teamId,
        NIMTeamType teamType, NIMTeamMemberQueryOption queryOption) async {
      return _platform.getTeamMemberList(teamId, teamType, queryOption);
    }
    
    参数名称 类型 是否必填 说明
    teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
    teamType NIMTeamType 群组类型,包括高级群和超大群。
    queryOption NIMTeamMemberQueryOption 群组成员分页查询选项。

    示例代码

    dartawait NimCore.instance.teamService.getTeamMemberList(teamId, teamType, queryOption);
    

    返回值

    NIMResult<NIMTeamMemberListResult>:群组成员查询结果

    相关回调

    getTeamMemberListByIds

    接口描述

    根据群成员账号批量获取群组成员列表。返回成员列表按照加入群组的时间戳(NIMTeamMember.joinTime)排序。

    SDK 获取策略如下:

    查询引用消息.drawio.png

    群组数据同步(onSyncFinished)完成前,可能获取不到完整数据。

    参数说明

    dartFuture<NIMResult<List<NIMTeamMember>>> getTeamMemberListByIds(
        String teamId, NIMTeamType teamType, List<String> accountIds) async {
      return _platform.getTeamMemberListByIds(teamId, teamType, accountIds);
    }
    
    参数名称 类型 是否必填 说明
    teamId String 群组 ID 列表,不可为空,否则返回 191004 参数错误。
    teamType NIMTeamType 群组类型,包括高级群和超大群。
    accountIds List<String> 群成员账号列表,不可为 null 或空,否则返回 191004 参数错误。

    示例代码

    dartawait NimCore.instance.teamService.getTeamMemberListByIds(teamId, teamType, accountIds);
    

    返回值

    NIMResult<List<NIMTeamMember>>:群成员列表

    相关回调

    getTeamMemberInvitor

    接口描述

    根据群成员账号获取群成员邀请人。

    SDK 获取策略如下:

    查询引用消息.drawio.png

    群组数据同步(onSyncFinished)完成前,可能获取不到完整数据。

    参数说明

    dartFuture<NIMResult<Map<String, String>>> getTeamMemberInvitor(
        String teamId, NIMTeamType teamType, List<String> accountIds) async {
      return _platform.getTeamMemberInvitor(teamId, teamType, accountIds);
    }
    
    参数名称 类型 是否必填 说明
    teamId String 群组 ID 列表,不可为空,否则返回 191004 参数错误。
    teamType NIMTeamType 群组类型,包括高级群和超大群。
    accountIds List<String> 群成员账号列表,不可为 null 或空,否则返回 191004 参数错误。

    示例代码

    dartawait NimCore.instance.teamService.getTeamMemberInvitor(teamId, teamType, accountIds);
    

    返回值

    NIMResult<Map<String, String>>:查询到的被邀请账号(accountId:invitorAccountId)

    相关回调

    getTeamJoinActionInfoList

    接口描述

    分页获取入群操作相关信息列表。返回列表按照入群请求时间戳(NIMTeamJoinActionInfo.timestamp)逆序排序。

    仅查询本地数据。

    参数说明

    dartFuture<NIMResult<NIMTeamJoinActionInfoResult>> getTeamJoinActionInfoList(
        NIMTeamJoinActionInfoQueryOption queryOption) async {
      return _platform.getTeamJoinActionInfoList(queryOption);
    }
    
    参数名称 类型 是否必填 说明
    queryOption NIMTeamJoinActionInfoQueryOption 入群操作信息查询选项。

    示例代码

    dartawait NimCore.instance.teamService.getTeamJoinActionInfoList(queryOption);
    

    返回值

    NIMResult<NIMTeamJoinActionInfoResult>:入群操作信息分页查询结果

    相关回调

    searchTeamByKeyword

    接口描述

    根据关键字搜索群信息(包括高级群和超大群)。

    • 仅匹配群组名称。
    • 不检验群组的有效性、是否加入。

    仅查询本地数据。

    参数说明

    dartFuture<NIMResult<List<NIMTeam>>> searchTeamByKeyword(String keyword) async {
      return _platform.searchTeamByKeyword(keyword);
    }
    
    参数名称 类型 是否必填 说明
    keyword String 搜索关键词。

    示例代码

    dartawait NimCore.instance.teamService.searchTeamByKeyword(keyword);
    

    返回值

    NIMResult<List<NIMTeam>>:群组列表

    相关回调

    searchTeamMembers

    接口描述

    根据关键字搜索群成员(包括高级群和超大群)。

    仅查询本地数据。

    参数说明

    dartFuture<NIMResult<NIMTeamMemberListResult>> searchTeamMembers(
        NIMTeamMemberSearchOption searchOption) async {
      return _platform.searchTeamMembers(searchOption);
    }
    
    参数名称 类型 是否必填 说明
    searchOption NIMTeamMemberSearchOption 搜索配置项。

    示例代码

    dartawait NimCore.instance.teamService.searchTeamMembers(searchOption);
    

    返回值

    NIMResult<NIMTeamMemberListResult>:分页获取群成员列表返回结果

    相关回调

    此文档是否对你有帮助?
    有帮助
    去反馈
    • API 概览
    • 群组监听
    • 群组操作
    • 接口类
    • add
    • cancel
    • createTeam
    • leaveTeam
    • updateTeamInfo
    • getTeamInfo
    • getTeamInfoByIds
    • dismissTeam
    • inviteMember
    • acceptInvitation
    • rejectInvitation
    • kickMember
    • applyJoinTeam
    • acceptJoinApplication
    • rejectJoinApplication
    • updateTeamMemberRole
    • transferTeamOwner
    • updateSelfTeamMemberInfo
    • updateTeamMemberNick
    • setTeamChatBannedMode
    • setTeamMemberChatBannedStatus
    • getJoinedTeamList
    • getJoinedTeamCount
    • getTeamMemberList
    • getTeamMemberListByIds
    • getTeamMemberInvitor
    • getTeamJoinActionInfoList
    • searchTeamByKeyword
    • searchTeamMembers