群成员管理

更新时间: 2024/11/18 16:22:47

网易云信 IM 支持用户查询、添加、移除群组成员,管理成员角色等功能,拥有完善的成员权限体系及管理功能,群组内所有用户根据权限分为群主、管理员、以及普通成员。

支持平台

本文内容适用的开发平台或框架如下表所示:

Android iOS macOS/Windows Web/uni-app/小程序 Node.js/Electron HarmonyOS Flutter
✔️️️ ✔️️️ ✔️️️ ✔️️️ ✔️️️ ✔️️️ ✔️

技术原理

网易云信 NIM SDK 提供管理群组成员的相关方法,帮助您快速实现和使用群组的成员权限体系及管理功能。

群组中有三种角色,群主(Owner),群组管理员(Manager)以及群组普通成员(Normal)。

  • 群主默认为群组创建者,后续可通过 transferTeamOwner 方法转让群主身份。
  • 群组管理员由群主分配和管理。用户进入群组后默认为普通成员,群主通过 updateTeamMemberRole 方法将成员修改为管理员,或将管理员降级为普通成员。

前提条件

管理群组管理员

通过调用 updateTeamMemberRole 方法添加或移除群组管理员。将普通成员角色修改为管理员即添加管理员,将管理员角色修改为普通成员即移除管理员。

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

群主添加管理员后,所有群成员会收到群组通知消息,通知消息类型为 “添加高级群/超大群管理员”。群主移除管理员后,所有群成员收到群组通知消息类型为 “移除高级群/超大群管理员”。

只有群主才拥有管理群组管理员的权限。

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
List<String> memberAccountIds = new ArrayList<>();
memberAccountIds.add("test1");
V2NIMTeamMemberRole memberRole = V2NIMTeamMemberRole.V2NIM_TEAM_MEMBER_ROLE_MANAGER;
v2TeamService.updateTeamMemberRole(teamId, teamType, memberAccountIds, memberRole, result -> {
    // 更新群组成员角色成功
}, error -> {
    // 更新群组成员角色失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] updateTeamMemberRole:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL memberAccountIds:@[@"accountId"] memberRole:V2NIM_TEAM_MEMBER_ROLE_NORMAL success:^{
    // 更新群组成员角色成功
} failure:^(V2NIMError * _Nonnull error) {
    // 更新群组成员角色失败
}];
macOS/Windows
C++std::vector<std::string> memberAccountIds;
memberAccountIds.push_back("account1");
teamService.updateTeamMemberRole(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    memberAccountIds,
    V2NIM_TEAM_MEMBER_ROLE_MANAGER,
    []() {
        // update team member role success
    },
    [](V2NIMError error) {
        // update team member role failed, handle error
    }
);
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.updateTeamMemberRole("123456", 1, ["accountId1"], 0)
Node.js/Electron
TypeScriptawait v2.teamService.updateTeamMemberRole(teamId, teamType, memberAccountIds, memberRole)
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const memberAccountIds: string[] = ["aaa", "bbb"]
  const memberRole: V2NIMTeamMemberRole = V2NIMTeamMemberRole.V2NIM_TEAM_MEMBER_ROLE_MANAGER

  await nim.teamService.updateTeamMemberRole(teamId, teamType, memberAccountIds, memberRole)
  // success
}
catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.updateTeamMemberRole(teamId, teamType, memberAccountIds, memberRole);

修改群成员信息

修改群成员昵称

通过调用 updateTeamMemberNick 来修改群组成员昵称。修改成功后,群组内所有成员会收到群成员信息变更回调 onTeamMemberInfoUpdated

只有群主和管理员才有修改群组成员昵称的权限。

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
String account = "test";
String teamNick = "test nick";
v2TeamService.updateTeamMemberNick(teamId, teamType, account, teamNick, result -> {
    // 修改群成员昵称成功
}, error -> {
    // 修改群成员昵称失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] updateTeamMemberNick:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL accountId:@"accountId" teamNick:@"test" success:^{
    // 修改群成员昵称成功
} failure:^(V2NIMError * _Nonnull error) {
    // 修改群成员昵称失败
}];
macOS/Windows
C++teamService.updateTeamMemberNick(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    "accountId",
    "new nick",
    []() {
        // update team member nick success
    },
    [](V2NIMError error) {
        // update team member nick failed, handle error
    });
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.updateTeamMemberNick("123456", 1, "accountId1", "test nick")
Node.js/Electron
TypeScriptawait v2.teamService.updateTeamMemberNick("123456", 1, "accountId1", "test nick")
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const account: string = "aaa"
  const nick: string = "new nick"

  await teamService.updateTeamMemberNick(teamId, teamType, account, nick)
  // success
} catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.updateTeamMemberNick(teamId, teamType, accountId, teamNick);

修改本人群信息

通过调用 updateSelfTeamMemberInfo 方法修改本人群成员信息。支持修改群成员昵称及服务端扩展字段。

修改本人群成员信息成功后,群组内所有成员收到群成员信息变更回调 onTeamMemberInfoUpdated

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
V2NIMUpdateSelfMemberInfoParams memberInfoParams = new V2NIMUpdateSelfMemberInfoParams();
memberInfoParams.setTeamNick("test nick");
memberInfoParams.setServerExtension("test");
v2TeamService.updateSelfTeamMemberInfo(teamId,teamType, memberInfoParams, result -> {
    // 修改自己的群成员信息成功
}, error -> {
    // 修改自己的群成员信息失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] updateSelfTeamMemberInfo:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL memberInfoParams:infoParams success:^{
    // 修改自己的群成员信息成功
} failure:^(V2NIMError * _Nonnull error) {
    // 修改自己的群成员信息失败
}];
macOS/Windows
C++V2NIMUpdateSelfMemberInfoParams memberInfoParams;
memberInfoParams.teamNick = "new nick";
teamService.updateSelfTeamMemberInfo(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    memberInfoParams,
    []() {
        // update self team member info success
    },
    [](V2NIMError error) {
        // update self team member info failed, handle error
    });
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.updateSelfTeamMemberInfo("123456", 1, {
  "teamNick": "test nick"
})
Node.js/Electron
TypeScriptawait v2.teamService.updateSelfTeamMemberInfo("123456", 1, {
  "teamNick": "test nick"
})
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const memberInfoParams: V2NIMUpdateSelfMemberInfoParams = {
    teamNick: "nick",
    serverExtension: "ext"
  }

  await teamService.updateSelfTeamMemberInfo(teamId, teamType, memberInfoParams)
  // success
} catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.updateSelfTeamMemberInfo(teamId, teamType, memberInfoParams);

禁言或解除禁言群组成员

禁言或解除禁言群组所有成员

通过调用 setTeamChatBannedMode 方法来禁言群组所有普通成员或解除所有普通成员的禁言。

设置成功后,群组内所有成员会收到群组信息变更回调 onTeamInfoUpdate 以及群信息变更的通知类消息,消息类型为 “高级群/超大群信息更新”。

  • 只有群主和管理员才有禁言普通成员(不含群主和管理员)或取消普通成员禁言的权限。
  • 该方法仅支持禁言所有普通成员,如需全员禁言(包含群主和群管理员),请调用服务端 API 更新群组信息

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
V2NIMTeamChatBannedMode chatBannedMode = V2NIMTeamChatBannedMode.V2NIM_TEAM_CHAT_BANNED_MODE_BANNED_NORMAL;
v2TeamService.setTeamChatBannedMode(teamId,teamType, chatBannedMode, result -> {
    // 设置群组禁言模式成功
}, error -> {
    // 设置群组禁言模式失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] setTeamChatBannedMode:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL chatBannedMode:V2NIM_TEAM_CHAT_BANNED_MODE_BANNED_NORMAL success:^{
    // 设置群组禁言模式成功
} failure:^(V2NIMError * _Nonnull error) {
    // 设置群组禁言模式失败
}];
macOS/Windows
C++teamService.setTeamChatBannedMode(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    V2NIM_TEAM_CHAT_BANNED_MODE_BANNED_NORMAL,
    []() {
        // set team chat banned mode success
    },
    [](V2NIMError error) {
        // set team chat banned mode failed, handle error
    });
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.setTeamChatBannedMode("123456", 1, 1)
Node.js/Electron
TypeScriptawait v2.teamService.setTeamChatBannedMode("123456", 1, 1)
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const chatBannedMode: V2NIMTeamChatBannedMode = V2NIMTeamChatBannedMode.V2NIM_TEAM_CHAT_BANNED_MODE_BANNED_NORMAL

  await teamService.setTeamChatBannedMode(this.teamId, this.teamType, this.chatBannedMode)
  // success
} catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.setTeamChatBannedMode(teamId, teamType, chatBannedMode);

禁言或解除禁言群组指定成员

通过调用 setTeamMemberChatBannedStatus 方法来禁言群组指定成员或解除群成员的禁言。

设置成功后,群组内所有成员会收到群成员信息变更回调 onTeamMemberInfoUpdated 以及群成员禁言的通知类消息,消息类型为 “禁言高级群/超大群成员”。

只有群主和管理员才能禁言普通成员。

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
String accountId = "test";
boolean chatBanned = true;
v2TeamService.setTeamMemberChatBannedStatus(teamId,teamType, accountId, chatBanned, result -> {
    // 设置群组成员聊天禁言状态成功
}, error -> {
    // 设置群组成员聊天禁言状态失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] setTeamMemberChatBannedStatus:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL accountId:@"accountId" chatBanned:YES success:^{
    // 设置群组成员聊天禁言状态成功
} failure:^(V2NIMError * _Nonnull error) {
    // 设置群组成员聊天禁言状态失败
}];
macOS/Windows
C++teamService.setTeamMemberChatBannedStatus(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    "accountId",
    true,
    []() {
        // set team member chat banned status success
    },
    [](V2NIMError error) {
        // set team member chat banned status failed, handle error
    });
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.setTeamMemberChatBannedStatus("123456", 1, "accountId1", true)
Node.js/Electron
TypeScriptawait v2.teamService.setTeamMemberChatBannedStatus("123456", 1, "accountId1", true)
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const account: string = "aaaa"
  const chatBanned: boolean = true

  await teamService.setTeamMemberChatBannedStatus(teamId, teamType, accountId, chatBanned)
  // success
} catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.setTeamMemberChatBannedStatus(teamId, teamType, accountId, chatBanned);

分页获取所有群组成员列表

通过调用 getTeamMemberList 方法分页获取群组所有群成员信息。

支持获取指定类型或被禁言的群成员:

  • roleQueryType:获取指定类型的群成员(必须指定)

  • onlyChatBannedtrue:获取被禁言的群成员

  • 由于群组成员数据较大,且除了进入群组成员列表界面外,其他场景不需要群组成员列表的数据,因此 SDK 不会在登录时同步群组成员数据,而是按照按需获取的原则,当上层主动调用获取指定群的群组成员列表时,才判断是否需要同步。
  • 该操作有可能只是从本地数据库读取缓存数据,也有可能会从服务器同步新的数据,因此耗时可能会比较长。

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
V2NIMTeamMemberQueryOption queryOption = new V2NIMTeamMemberQueryOption();
queryOption.setRoleQueryType(V2NIMTeamMemberRoleQueryType.V2NIM_TEAM_MEMBER_ROLE_QUERY_TYPE_ALL);
// 设置分页偏移,首次传"",后续拉取采用上一次返回的 nextToken
queryOption.setNextToken("");
queryOption.setDirection(V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC);
queryOption.setLimit(100);
queryOption.setOnlyChatBanned(false);
v2TeamService.getTeamMemberList(teamId, teamType, queryOption, result -> {
    // 获取群组成员列表成功
}, error -> {
    // 获取群组成员列表失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] getTeamMemberList:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL queryOption:queryOption success:^(V2NIMTeamMemberListResult * _Nonnull result) {
    // 获取群组成员列表成功
} failure:^(V2NIMError * _Nonnull error) {
    // 获取群组成员列表失败
}];
macOS/Windows
C++V2NIMTeamMemberQueryOption queryOption;
queryOption.nextToken = ""; // first page
queryOption.limit = 10;
queryOption.direction = V2NIM_QUERY_DIRECTION_DESC;
teamService.getTeamMemberList(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    queryOption,
    [](V2NIMTeamMemberListResult result) {
        // get team members success
    },
    [](V2NIMError error) {
        // get team members failed, handle error
    });
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.getTeamMemberList(
  "123456",
  1,
  {
    "roleQueryType": 0,
    "onlyChatBanned": false,
    "direction": 0,
    "limit": 100,
    "nextToken": ""
  }
)
Node.js/Electron
TypeScriptconst result = await v2.teamService.getTeamMemberList(teamId, teamType, {
    "roleQueryType": 0,
    "onlyChatBanned": false,
    "direction": 0,
    "limit": 100,
    "nextToken": ""
  }
)
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const queryOption: V2NIMTeamMemberQueryOption = {
    roleQueryType: V2NIMTeamMemberRoleQueryType.V2NIM_TEAM_MEMBER_ROLE_QUERY_TYPE_NORMAL,
    onlyChatBanned: false,
    direction: V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC
    limit: 50
    nextToken: undefined
  }

  const memberListResult: V2NIMTeamMemberListResult = await nim.teamService.getTeamMemberList(teamId, teamType, queryOption)
  // success
} catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.getTeamMemberList(teamId, teamType, queryOption);

批量获取指定群组成员列表

通过调用 getTeamMemberListByIds 方法批量获取指定群成员信息。

SDK 获取策略如下:

查询引用消息.drawio.png

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
List<String> accountIds = new ArrayList<>();
accountIds.add("test1");
accountIds.add("test2");
v2TeamService.getTeamMemberListByIds(teamId,teamType, accountIds, result -> {
    // 获取群组成员列表成功
}, error -> {
    // 获取群组成员列表失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] getTeamMemberListByIds:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL accountIds:@[@"accountId"] success:^(NSArray<V2NIMTeamMember *> * _Nonnull memberList) {
    // 获取群组成员列表成功
} failure:^(V2NIMError * _Nonnull error) {
    // 获取群组成员列表失败
}];
macOS/Windows
C++nstd::vector<nstd::string> accountIds;
accountIds.push_back("account1");
accountIds.push_back("account2");
teamService.getTeamMemberListByIds(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    accountIds,
    [](nstd::vector<V2NIMTeamMember> memberList) {
        // get team members by account ids success
    },
    [](V2NIMError error) {
        // get team members by account ids failed, handle error
    });
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.getTeamMemberListByIds("123456", 1, ["accountId1"])
Node.js/Electron
TypeScriptconst members = await v2.teamService.getTeamMemberListByIds(teamId, teamType, accountIds)
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const accounts = ["aaa", "bbb"]

  const members: V2NIMTeamMember[] = await nim.teamService.getTeamMemberListByIds(teamId, teamType, accountIds)
  // success
} catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.getTeamMemberListByIds(teamId, teamType, accountIds);

查询群成员的邀请者

通过调用 getTeamMemberInvitor 获取群组成员的入群邀请人。

SDK 获取策略如下:

查询引用消息.drawio.png

群成员入群邀请人为空表示主动入群,没有邀请人。

示例代码

Android
JavaV2NIMTeamService v2TeamService = NIMClient.getService(V2NIMTeamService.class);
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
List<String> accountIds = new ArrayList<>();
accountIds.add("test1");
accountIds.add("test2");
v2TeamService.getTeamMemberInvitor(teamId,teamType, accountIds, result -> {
    // 获取群组成员邀请人成功
}, error -> {
    // 获取群组成员邀请人失败
});
iOS
Objective-C[[[NIMSDK sharedSDK] v2TeamService] getTeamMemberInvitor:@"teamId" teamType:V2NIM_TEAM_TYPE_NORMAL accountIds:@[@"accountId"] success:^(NSDictionary<NSString *,NSString *> * _Nonnull result) {
        // 获取群组成员邀请人成功
    } failure:^(V2NIMError * _Nonnull error) {
        // 获取群组成员邀请人失败
}];
macOS/Windows
C++nstd::vector<nstd::string> accountIds;
accountIds.push_back("account1");
accountIds.push_back("account2");
teamService.getTeamMemberInvitor(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    accountIds,
    [](nstd::map<nstd::string, nstd::string> invitors) {
        // get team member invitor success
    },
    [](V2NIMError error) {
        // get team member invitor failed, handle error
    });
Web/uni-app/小程序
TypeScriptawait nim.V2NIMTeamService.getTeamMemberInvitor("123456", 1, ["accountId1"])
Node.js/Electron
TypeScriptconst invitorMap = await v2.teamService.getTeamMemberInvitor(teamId, teamType, accountIds)
HarmonyOS
TypeScripttry {
  const teamId: string = "123456"
  const teamType: V2NIMTeamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL
  const accounts = ["aaa", "bbb"]

  const keyValue = await nim.teamService.getTeamMemberInvitor(teamId, teamType, accountIds)
  // success
} catch (err) {
  // fail
}
Flutter
dartawait NimCore.instance.teamService.getTeamMemberInvitor(teamId, teamType, accountIds);

根据关键字搜索群成员

通过调用 searchTeamMembers 方法,根据关键词搜索群组成员。

  • 关键词仅匹配群成员昵称。
  • 仅查询本地数据。

如果群组数据同步已开始,请在群组数据同步结束后进行该操作,否则可能获取不到完整数据。

示例代码:

Android
JavaV2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
String nextToken = "";
V2NIMTeamMemberSearchOption searchOption = V2NIMTeamMemberSearchOption.V2NIMTeamMemberSearchOptionBuilder.builder(keyword, teamType, nextToken)
        // 按需配置
//                .withLimit()
//                .withOrder()
//                .withTeamId()
        .build();
NIMClient.getService(V2NIMTeamService.class).searchTeamMembers(searchOption, new V2NIMSuccessCallback<V2NIMTeamMemberSearchResult>() {
    @Override
    public void onSuccess(V2NIMTeamMemberSearchResult v2NIMTeamMemberSearchResult) {

    }
}, new V2NIMFailureCallback() {
    @Override
    public void onFailure(V2NIMError error) {

    }
});
iOS
Objective-C- (void)searchMember
{
    V2NIMTeamMemberSearchOption *option = [[V2NIMTeamMemberSearchOption alloc] init];
    option.keyword = @"keyword"; // keyword
    option.teamType = V2NIM_TEAM_TYPE_NORMAL; // search all normal team
    option.teamType = V2NIM_TEAM_TYPE_SUPER; // search all super team
    option.teamId = @"123456"; // search specific team
    option.limit = 20; // limit
    option.order = V2NIM_SORT_ORDER_DESC;
    option.nextToken = V2NIMTeamMemberSearchOption.initNextToken; // init

    [NIMSDK.sharedSDK.v2TeamService searchTeamMembers:option success:^(V2NIMTeamMemberSearchResult * _Nonnull result) {
        // result
        result.memberList;

        if (result.finished) {
            // end
        } else {
            V2NIMTeamMemberSearchOption *nextOption = [option copy];
            // move next
            nextOption.nextToken = result.nextToken;

            // again
            [NIMSDK.sharedSDK.v2TeamService searchTeamMembers:nextOption success:^(V2NIMTeamMemberSearchResult * _Nonnull result) {

            } failure:^(V2NIMError * _Nonnull error) {

            }];
        }
    } failure:^(V2NIMError * _Nonnull error) {
        // error
    }];
}
macOS/Windows
C++V2NIMTeamMemberSearchOption option;
option.keyword = "keyword";
option.teamType = V2NIM_TEAM_TYPE_NORMAL;
option.pageToken = "";
teamService.searchTeamMembers(
    option,
    [](nstd::vector<V2NIMTeamMember> teamMembers) {
        // search team members success
    },
    [](V2NIMError error) {
        // search team members failed, handle error
    });
Node.js/Electron
TypeScriptconst teamId: string = this.teamId
const teamType: V2NIMTeamType = this.teamType
const initNextToken: string = this.initNextToken
const order: V2NIMSortOrder = this.order
const limit: number = this.order
const keyword: string = this.keyword
const nextToken: string = this.nextToken
const options = {
  keyword: keyword,
  teamId: teamId,
  teamType: teamType,
  nextToken: nextToken,
  initNextToken: initNextToken,
  limit: limit,
  order: order
} as V2NIMTeamMemberSearchOption

const result = await v2.teamService.searchTeamMembers(option)

HarmonyOS
Typescriptconst teamId: string = this.teamId
const teamType: V2NIMTeamType = this.teamType
const initNextToken: string = this.initNextToken
const order: V2NIMSortOrder = this.order
const limit: number = this.order
const keyword: string = this.keyword
const nextToken: string = this.nextToken
const options = {
  keyword: keyword,
  teamId: teamId,
  teamType: teamType,
  nextToken: nextToken,
  initNextToken: initNextToken,
  limit: limit,
  order: order
} as V2NIMTeamMemberSearchOption

const res = await nim.teamService.searchTeamMembers(options)
Flutter
dartawait NimCore.instance.teamService.searchTeamMembers(searchOption);

群成员特别关注

在群组中,用户为了减少消息提醒的打扰,会对群设置免打扰,开启后,对于群组中的消息不会有提醒。为了使用户在群组免打扰状态下,仍能收到特定成员的消息提醒。云信 IM 支持设置群成员特别关注。

当前支持配置的群消息提醒方式如下:

  • 全部提醒(默认),即不开启免打扰
  • 仅群主/管理员消息提醒
  • 全部不提醒

当开启群消息免打扰时:

  • 设置为 “仅群主/管理员消息提醒”,且设置了特别关注成员,则当群主、管理员、特别关注成员发送消息,会收到消息提醒。
  • 设置为 “全部不提醒”,且设置了特别关注成员,则只有特别关注成员发送消息,才会收到消息提醒。
  • 如果特别关注成员离开群组, 则特别关注列表移除该成员,如果关注成员离开后又加入,不会再添加进特别关注列表。
  • 当不开启群消息免打扰时,如果特别关注列表不为空,则忽略特别关注成员。

您可以调用 addTeamMembersFollow 方法在群组(包括高级群和超大群)设置免打扰的情况下,设置需要特别关注的群成员。您也可以调用 removeTeamMembersFollow 方法移除群组中特别关注成员列表。移除成功后,当群组设置免打扰时,将无法接接收到消息提醒。

设置完成后,都会触发 onTeamMemberInfoUpdated 回调。

示例代码如下:

Android
java// 添加特别关注成员
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
List<String> accountIds = new ArrayList<>();
accountIds.add("test1");
accountIds.add("test2");
NIMClient.getService(V2NIMTeamService.class).addTeamMembersFollow(teamId, teamType, accountIds, new V2NIMSuccessCallback<Void>() {
  @Override
  public void onSuccess(Void unused) {
   //addTeamMembersFollow success
  }
}, new V2NIMFailureCallback() {
  @Override
  public void onFailure(V2NIMError error) {
   //addTeamMembersFollow failed
  }
});

// 移除特别关注成员
String teamId = "123456";
V2NIMTeamType teamType = V2NIMTeamType.V2NIM_TEAM_TYPE_NORMAL;
List<String> accountIds = new ArrayList<>();
accountIds.add("test1");
accountIds.add("test2");
NIMClient.getService(V2NIMTeamService.class).removeTeamMembersFollow(teamId, teamType, accountIds, new V2NIMSuccessCallback<Void>() {
  @Override
  public void onSuccess(Void unused) {
   //removeTeamMembersFollow success
  }
}, new V2NIMFailureCallback() {
  @Override
  public void onFailure(V2NIMError error) {
   //removeTeamMembersFollow failed
  }
});
iOS
Objective-C//添加特别关注成员
[[NIMSDK sharedSDK].v2TeamService addTeamMembersFollow:@"teamId"
                                                teamType:V2NIM_TEAM_TYPE_NORMAL
                                            accountIds:@[@"accountId1", @"accountId2"]
                                                success:^{
    // on success
} failure:^(V2NIMError * _Nonnull error) {
    // on failure
}];

//移除特别关注成员
[[NIMSDK sharedSDK].v2TeamService removeTeamMembersFollow:@"teamId"
                                                    teamType:V2NIM_TEAM_TYPE_NORMAL
                                                accountIds:@[@"accountId1", @"accountId2"]
                                                    success:^{
    // on success
} failure:^(V2NIMError * _Nonnull error) {
    // on failure
}];
macOS/Windows
C++//添加特别关注成员
nstd::vector<nstd::string> accountIds;
accountIds.push_back("account1");
teamService.addTeamMembersFollow(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    accountIds,
    []() {
        // add team members follow success
    },
    [](V2NIMError error) {
        // add team members follow failed, handle error
    });
//移除特别关注成员
nstd::vector<nstd::string> accountIds;
accountIds.push_back("account1");
teamService.removeTeamMembersFollow(
    "teamId",
    V2NIM_TEAM_TYPE_NORMAL,
    accountIds,
    []() {
        // remove team members follow success
    },
    [](V2NIMError error) {
        // remove team members follow failed, handle error
    });
Web/uni-app/小程序
TypeScript//添加特别关注成员
const teamId = "YOUR_TEAM_ID"
const teamType = 1 // "YOUR_TEAM_TYPE"
const accountIds = ["TARGET_ACCOUNT_ID"]
await nim.V2NIMTeamService.addTeamMembersFollow(teamId, teamType, accountIds)
//移除特别关注成员
const teamId = "YOUR_TEAM_ID"
const teamType = 1 // "YOUR_TEAM_TYPE"
const accountIds = ["TARGET_ACCOUNT_ID"]
await nim.V2NIMTeamService.removeTeamMembersFollow(teamId, teamType, accountIds)
Node.js/Electron
TypeScript//添加特别关注成员
const teamId = "YOUR_TEAM_ID"
const teamType = 1 // "YOUR_TEAM_TYPE"
const accountIds = ["TARGET_ACCOUNT_ID"]
await v2.teamService.addTeamMembersFollow(teamId, teamType, accountIds)
//移除特别关注成员
const teamId = "YOUR_TEAM_ID"
const teamType = 1 // "YOUR_TEAM_TYPE"
const accountIds = ["TARGET_ACCOUNT_ID"]
await v2.teamService.removeTeamMembersFollow(teamId, teamType, accountIds)

涉及接口

Android/iOS/macOS/Windows/Web/uni-app/小程序/Node.js/Electron/HarmonyOS
API 说明
transferTeamOwner 转让群主身份
updateTeamMemberRole 修改群成员角色
updateTeamMemberNick 修改群成员昵称
updateSelfTeamMemberInfo 修改自己的群成员信息
setTeamChatBannedMode 设置群组禁言模式
setTeamMemberChatBannedStatus 设置群成员聊天禁言状态
getTeamMemberList 分页获取群组成员列表
getTeamMemberListByIds 根据账号批量获取群组成员列表
getTeamMemberInvitor 根据账号获取群组成员邀请人
searchTeamMembers 根据关键字搜索群成员(包括高级群和超大群)
addTeamMembersFollow 添加特别关注的群成员列表
removeTeamMembersFollow 移除特别关注的群成员列表
Flutter
API 说明
transferTeamOwner 转让群主身份
updateTeamMemberRole 修改群成员角色
updateTeamMemberNick 修改群成员昵称
updateSelfTeamMemberInfo 修改自己的群成员信息
setTeamChatBannedMode 设置群组禁言模式
setTeamMemberChatBannedStatus 设置群成员聊天禁言状态
getTeamMemberList 分页获取群组成员列表
getTeamMemberListByIds 根据账号批量获取群组成员列表
getTeamMemberInvitor 根据账号获取群组成员邀请人
searchTeamMembers 根据关键字搜索群成员(包括高级群和超大群)
此文档是否对你有帮助?
有帮助
去反馈
  • 支持平台
  • 技术原理
  • 前提条件
  • 管理群组管理员
  • 修改群成员信息
  • 修改群成员昵称
  • 修改本人群信息
  • 禁言或解除禁言群组成员
  • 禁言或解除禁言群组所有成员
  • 禁言或解除禁言群组指定成员
  • 分页获取所有群组成员列表
  • 批量获取指定群组成员列表
  • 查询群成员的邀请者
  • 根据关键字搜索群成员
  • 群成员特别关注
  • 涉及接口