频道管理

更新时间: 2023/06/27 07:19:29

使用限制

  • 单个服务器的频道数量上限默认为 100 个。

    可在云信控制台配置单个服务器的频道数量上限在云信控制台选择应用,进入IM 专业版 > 功能权限开通 > 拓展配置 > 圈组 > 高级配置 > 单server可创建的channel数即可配置。
  • 拥有管理频道的权限(kPermissionManageChannel)才能创建、修改和删除频道。权限通过身份组进行配置和管理,具体请参见身份组概述及其他身份组相关文档。

创建频道

功能介绍

调用 CreateChannel方法创建频道。

参数说明

以下仅列出个别重要参数:

参数 类型 说明
anti_spam_info QChatBusinessAntiSpamInfo 配置反垃圾信息,可配置反垃圾文本业务 ID 或 反垃圾图片业务 ID。
visitor_mode NIMQChatChannelVisitorMode 设置频道是否对游客可见:
  • kNIMQChatChannelVisitorModeVisible:可见
  • kNIMQChatChannelVisitorModeInvisible:不可见
  • kNIMQChatChannelVisitorModeFollow:跟随模式(默认),即如果该频道的查看模式(view_mode)被设置为“公开”则该频道对游客可见,如果被设置为“私密”则对游客不可见
如果频道的 visitor_mode 为跟随模式,且同步模式(sync_mode)为“与频道分组同步”,则当该频道所属的频道分组的查看模式(view_mode)变更后,该频道对游客的可见性也将变更。例如,在这种情况下,频道分组的查看模式由公开变为私密,则此时该频道对游客从“可见”变为“不可见”。

示例代码

cppQChatChannelCreateParam param;
param.channel_info.server_id = 123456;
param.channel_info.name = "channel name";
param.channel_info.topic = "channel topic";
param.channel_info.custom = "channel custom";
param.channel_info.type = kNIMQChatChannelTypeText;
param.channel_info.view_mode = kNIMQChatChannelViewModePublic;
param.channel_info.visitor_mode = kNIMQChatChannelVisitorModeVisible;
param.anti_spam_info.text_bid = "anti spam text business id";
param.anti_spam_info.pic_bid = "anti spam pic business id";
param.cb = [this](const QChatChannelCreateResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::CreateChannel(param);

删除频道

功能介绍

调用 DeleteChannel 方法删除频道。

示例代码

cppQChatChannelDeleteParam param;
param.channel_id = 123456;
param.cb = [this, param](const QChatChannelDeleteResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::DeleteChannel(param);

更新频道

功能介绍

调用 UpdateChannel 方法更新频道。

参数说明

参数 类型 说明
anti_spam_info QChatBusinessAntiSpamInfo 配置反垃圾信息,可配置反垃圾文本业务 ID 或 反垃圾图片业务 ID。
visitor_mode NIMQChatChannelVisitorMode 设置频道是否对游客可见:
  • kNIMQChatChannelVisitorModeVisible:可见
  • kNIMQChatChannelVisitorModeInvisible:不可见
  • kNIMQChatChannelVisitorModeFollow:跟随模式(默认),即如果该频道的查看模式(view_mode)被设置为“公开”则该频道对游客可见,如果被设置为“私密”则对游客不可见
如果频道的 visitor_mode 为跟随模式,且同步模式(sync_mode)为“与频道分组同步”,则当该频道所属的频道分组的查看模式(view_mode)变更后,该频道对游客的可见性也将变更。例如,在这种情况下,频道分组的查看模式由公开变为私密,则此时该频道对游客从“可见”变为“不可见”。

示例代码

cppQChatChannelUpdateParam param;
param.channel_id = 123456;
param.name = "channel name";
param.topic = "channel topic";
param.custom = "channel custom";
param.view_mode = kNIMQChatChannelViewModePublic;
param.visitor_mode = kNIMQChatChannelVisitorModeVisible;
param.anti_spam_info.text_bid = "anti spam text business id";
param.anti_spam_info.pic_bid = "anti spam pic business id";
param.cb = [this](const QChatChannelUpdateResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::UpdateChannel(param);

查询频道

按照频道ID查询

功能介绍

调用 GetChannels 方法查询频道列表。

示例代码

cppQChatChannelGetChannelsParam param;
param.channel_ids= {123, 456}
param.cb = [this](const QChatChannelGetChannelsResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetChannels(param);

按照时间分页查询

功能介绍

调用 GetChannelsByPage 方法查询频道列表(分页)。

示例代码

cppQChatChannelGetChannelsPageParam param;
param.server_id = 123456;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetChannelsPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetChannelsByPage(param);

查询频道成员列表

功能介绍

调用 GetMembersByPage 方法查询频道用户列表(分页)。

示例代码

cppQChatChannelGetMembersPageParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetMembersPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetMembersByPage(param);

订阅频道

功能介绍

调用 Subscribe 方法订阅频道未读状态、未读数或未读消息。

示例代码

cppQChatChannelSubscribeParam param;
param.ope_type = kNIMQChatSubscribeOpeTypeSubscribe;
param.sub_type = kNIMQChatSubscribeTypeMsg;
NIMQChatChannelIDInfo id_info;
id_info.server_id = 123456;
id_info.channel_id = 123456;
param.id_infos.push_back(id_info);
param.cb = [this](const QChatChannelSubscribeResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::Subscribe(param);

白/黑名单

更新白/黑名单成员

功能介绍

调用 UpdateWhiteBlackMembers 方法更新频道白/黑名单成员。

单个频道的黑白名单成员人数上限,默认为 1000。可在云信控制台配置该数量上限,配置路径:在云信控制台选择应用,进入IM 免费版/专业版 > 功能权限开通 > 拓展配置 > 圈组 > 高级配置 > 公开私密频道的黑白名单成员数

公开频道更新的为黑名单;私有频道更新的为白名单。

示例代码

cppQChatChannelUpdateWhiteBlackMembersParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.accids = {"accid1", "accid2"};
param.type = kNIMQChatChannelBlack;
param.ope_type = kNIMQChatChannelWhiteOpeTypeAdd;
param.cb = [this](const QChatChannelUpdateWhiteBlackMembersResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::UpdateWhiteBlackMembers(param);

更新白/黑名单身份组

功能介绍

您可通 UpdateWhiteBlackRole 方法更新频道白/黑名单身份组。

单个频道可设置的黑白名单身份组的数量上限,默认为 20。

可在云信控制台配置该数量上限在云信控制台选择应用,进入IM 免费版/专业版 > 功能权限开通 > 拓展配置 > 圈组 > 高级配置 > channel公开私密频道的黑白名单身份组对象数即可配置。

公开频道更新的为黑名单;私有频道更新的为白名单。

示例代码

cppQChatChannelUpdateWhiteBlackRoleParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.role_id = 123456;
param.type = kNIMQChatChannelBlack;
param.ope_type = kNIMQChatChannelWhiteOpeTypeAdd;
param.cb = [this](const QChatChannelUpdateWhiteBlackRoleResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::UpdateWhiteBlackRole(param);

查询白/黑名单成员

功能介绍

调用 GetWhiteBlackMembersPage 方法查询频道白/黑名单成员列表(分页)。

示例代码

cppQChatChannelGetWhiteBlackMembersPageParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.type = kNIMQChatChannelBlack;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetWhiteBlackMembersPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetWhiteBlackMembersPage(param);

查询白/黑名单身份组

功能介绍

调用 GetWhiteBlackRolesPage 方法查询频道白/黑名单身份组列表(分页)。

示例代码

cppQChatChannelGetWhiteBlackRolesPageParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.type = kNIMQChatChannelBlack;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetWhiteBlackRolesPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetWhiteBlackRolesPage(param);

查询已存在白/黑名单成员

功能介绍

通过 GetExistingWhiteBlackMembers 方法,您可根据成员ID查询已存在的白/黑名单成员。

示例代码

cppQChatChannelGetExistingWhiteBlackMembersParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.type = kNIMQChatChannelBlack;
param.accids= {"accid1", "accid2"};
param.cb = [this](const QChatChannelGetExistingWhiteBlackMembersResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetExistingWhiteBlackMembers(param);

查询已存在白/黑名单身份组

功能介绍

通过GetExistingWhiteBlackRoles方法, 您可根据身份组ID查询已存在的白/黑名单身份组。

示例代码

cppQChatChannelGetExistingWhiteBlackRolesParam param;
param.server_id = params["server_id"].asUInt64();
param.channel_id = params["channel_id"].asUInt64();
param.type = (NIMQChatChannelWhiteBlackType)params["type"].asUInt();
param.role_ids = {123, 456};
param.cb = [this](const QChatChannelGetExistingWhiteBlackRolesResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetExistingWhiteBlackRoles(param);

查询未读数

功能介绍

通过 QueryUnreadInfo 方法,您可批量查询消息未读数。

  • 该方法调用存在频控,200ms 内最多可调用一次。
  • 单次最多查询频道数量为 100。

示例代码

cppQChatChannelQueryUnreadInfoParam param;
NIMQChatChannelIDInfo id_info;
id_info.server_id = 123456;
id_info.channel_id = 123456;
param.id_infos.push_back(id_info);
param.cb = [this](const QChatChannelQueryUnreadInfoResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::QueryUnreadInfo(param);

未读数回调

功能介绍

调用 RegUnreadCb 方法注册未读数变更回调

示例代码

cppQChatChannelRegUnreadCbParam reg_unread_cb_param;
reg_unread_cb_param.cb = [this](const QChatChannelUnreadResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::RegUnreadCb(reg_unread_cb_param);
此文档是否对你有帮助?
有帮助
去反馈
  • 使用限制
  • 创建频道
  • 功能介绍
  • 参数说明
  • 示例代码
  • 删除频道
  • 功能介绍
  • 示例代码
  • 更新频道
  • 功能介绍
  • 参数说明
  • 示例代码
  • 查询频道
  • 按照频道ID查询
  • 功能介绍
  • 示例代码
  • 按照时间分页查询
  • 功能介绍
  • 示例代码
  • 查询频道成员列表
  • 功能介绍
  • 示例代码
  • 订阅频道
  • 功能介绍
  • 示例代码
  • 白/黑名单
  • 更新白/黑名单成员
  • 功能介绍
  • 示例代码
  • 更新白/黑名单身份组
  • 功能介绍
  • 示例代码
  • 查询白/黑名单成员
  • 功能介绍
  • 示例代码
  • 查询白/黑名单身份组
  • 功能介绍
  • 示例代码
  • 查询已存在白/黑名单成员
  • 功能介绍
  • 示例代码
  • 查询已存在白/黑名单身份组
  • 功能介绍
  • 示例代码
  • 查询未读数
  • 功能介绍
  • 示例代码
  • 未读数回调
  • 功能介绍
  • 示例代码