频道管理
功能简介
频道(Channel)是社群内聊天互动的基本载体,功能类似传统群组,每个社群可包含多个频道。ZIM SDK 提供了完整的频道管理能力,支持以下功能:
- 创建/解散频道
- 更新频道名称、头像、公告
- 设置/删除频道自定义属性
- 查询频道信息及列表
- 设置频道禁言状态
- 监听频道列表变更与信息更新
前提条件
- 请参考 实现基本消息收发 完成 ZIM SDK 获取、初始化和用户登录。
- 请参考 使用 Token 鉴权 实现用户鉴权登录。
- 社群功能需要 ZIM SDK 3.0.0 及以上版本。
- 社群功能为旗舰版功能,使用前请联系 ZEGO 技术支持开通。
- 社群功能的 Token 生成方式与其他 ZIM 功能一致,无需额外权限声明。
频道类型说明
| 类型 | 说明 | 加入方式 | 可见性 |
|---|
| GENERAL | 默认频道,创建社群时自动创建,社群级别的 Tips 和通知会发在此频道 | 自动加入 | 所有成员可见 |
| PUBLIC | 公开频道,需要创建社群之后再创建 | 自动加入 | 所有成员可见 |
GENERAL 和 PUBLIC 功能完全一样,区别仅在于创建时机:GENERAL 在创建社群时自动创建,PUBLIC 需要在创建社群后手动创建。
创建频道
加入社群后,调用 createCommunityChannel 接口,传入频道基础信息 ZIMCommunityChannelInfo 与创建配置 ZIMCommunityChannelCreateConfig 在指定社群中创建频道。
- 只有社群群主和管理员有权限创建频道。
- 创建社群时系统会自动创建一个类型为
GENERAL 的默认频道;开发者可以在此基础上创建更多公开频道(PUBLIC)。
channelID 支持开发者自定义,仅支持数字、英文字符及以下特殊字符:! # $ % & ( ) + - : ; < = . > ? @ [ ] ^ _ { } | ~,但不能以 # 开头。若不填,ZIM 服务端会创建以 #C 开头的 channelID 的频道。
- 创建成功后即已加入频道,无需再调用加入接口。
示例代码
import im.zego.zim.ZIM;
import im.zego.zim.callback.ZIMCommunityChannelCreatedCallback;
import im.zego.zim.entity.ZIMCommunityChannelCreateConfig;
import im.zego.zim.entity.ZIMCommunityChannelFullInfo;
import im.zego.zim.entity.ZIMCommunityChannelInfo;
import im.zego.zim.entity.ZIMError;
import im.zego.zim.enums.ZIMErrorCode;
ZIMCommunityChannelInfo channelInfo = new ZIMCommunityChannelInfo();
channelInfo.setChannelID("channel_001"); // 频道 ID,可自定义
channelInfo.setChannelName("公告频道"); //最大长度300字符,可配置
channelInfo.setChannelAvatarUrl("https://example.com/channel_avatar.png"); //最大长度100字符,可配置
channelInfo.setCommunityID(communityID); // 所属社群 ID
ZIMCommunityChannelCreateConfig config = new ZIMCommunityChannelCreateConfig();
config.setChannelNotice("这是频道公告"); //最大长度500字符,可配置
HashMap<String, String> channelAttributes = new HashMap<>();
channelAttributes.put("type", "announcement");
config.setChannelAttributes(channelAttributes);
zim.createCommunityChannel(channelInfo, config, new ZIMCommunityChannelCreatedCallback() {
@Override
public void onCommunityChannelCreated(ZIMCommunityChannelFullInfo channelFullInfo, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 创建成功,channelFullInfo 包含频道完整信息
// 通过 channelFullInfo.conversationID 可获取用于收发消息的会话 ID
}
}
});
import im.zego.zim.ZIM;
import im.zego.zim.callback.ZIMCommunityChannelCreatedCallback;
import im.zego.zim.entity.ZIMCommunityChannelCreateConfig;
import im.zego.zim.entity.ZIMCommunityChannelFullInfo;
import im.zego.zim.entity.ZIMCommunityChannelInfo;
import im.zego.zim.entity.ZIMError;
import im.zego.zim.enums.ZIMErrorCode;
ZIMCommunityChannelInfo channelInfo = new ZIMCommunityChannelInfo();
channelInfo.setChannelID("channel_001"); // 频道 ID,可自定义
channelInfo.setChannelName("公告频道"); //最大长度300字符,可配置
channelInfo.setChannelAvatarUrl("https://example.com/channel_avatar.png"); //最大长度100字符,可配置
channelInfo.setCommunityID(communityID); // 所属社群 ID
ZIMCommunityChannelCreateConfig config = new ZIMCommunityChannelCreateConfig();
config.setChannelNotice("这是频道公告"); //最大长度500字符,可配置
HashMap<String, String> channelAttributes = new HashMap<>();
channelAttributes.put("type", "announcement");
config.setChannelAttributes(channelAttributes);
zim.createCommunityChannel(channelInfo, config, new ZIMCommunityChannelCreatedCallback() {
@Override
public void onCommunityChannelCreated(ZIMCommunityChannelFullInfo channelFullInfo, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 创建成功,channelFullInfo 包含频道完整信息
// 通过 channelFullInfo.conversationID 可获取用于收发消息的会话 ID
}
}
});
示例代码
ZIMCommunityChannelInfo *channelInfo = [[ZIMCommunityChannelInfo alloc] init];
channelInfo.channelID = @"channel_001";
channelInfo.channelName = @"公告频道"; //最大长度300字符,可配置
channelInfo.channelAvatarUrl = @"https://example.com/channel_avatar.png"; //最大长度100字符,可配置
channelInfo.communityID = communityID;
ZIMCommunityChannelCreateConfig *config = [[ZIMCommunityChannelCreateConfig alloc] init];
config.channelNotice = @"这是频道公告"; //最大长度500字符,可配置
config.channelAttributes = @{@"type": @"announcement"};
[zim createCommunityChannel:channelInfo config:config callback:^(ZIMCommunityChannelFullInfo * _Nonnull channelFullInfo, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 创建成功
}
}];
ZIMCommunityChannelInfo *channelInfo = [[ZIMCommunityChannelInfo alloc] init];
channelInfo.channelID = @"channel_001";
channelInfo.channelName = @"公告频道"; //最大长度300字符,可配置
channelInfo.channelAvatarUrl = @"https://example.com/channel_avatar.png"; //最大长度100字符,可配置
channelInfo.communityID = communityID;
ZIMCommunityChannelCreateConfig *config = [[ZIMCommunityChannelCreateConfig alloc] init];
config.channelNotice = @"这是频道公告"; //最大长度500字符,可配置
config.channelAttributes = @{@"type": @"announcement"};
[zim createCommunityChannel:channelInfo config:config callback:^(ZIMCommunityChannelFullInfo * _Nonnull channelFullInfo, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 创建成功
}
}];
示例代码
zim::ZIMCommunityChannelInfo channelInfo;
channelInfo.channelID = "channel_001";
channelInfo.channelName = "公告频道"; //最大长度300字符,可配置
channelInfo.channelAvatarUrl = "https://example.com/channel_avatar.png"; //最大长度100字符,可配置
channelInfo.communityID = communityID;
zim::ZIMCommunityChannelCreateConfig config;
config.channelNotice = "这是频道公告"; //最大长度500字符,可配置
config.channelAttributes["type"] = "announcement";
zim_->createCommunityChannel(channelInfo, config,
[=](const zim::ZIMCommunityChannelFullInfo &channelFullInfo,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 创建成功
}
});
zim::ZIMCommunityChannelInfo channelInfo;
channelInfo.channelID = "channel_001";
channelInfo.channelName = "公告频道"; //最大长度300字符,可配置
channelInfo.channelAvatarUrl = "https://example.com/channel_avatar.png"; //最大长度100字符,可配置
channelInfo.communityID = communityID;
zim::ZIMCommunityChannelCreateConfig config;
config.channelNotice = "这是频道公告"; //最大长度500字符,可配置
config.channelAttributes["type"] = "announcement";
zim_->createCommunityChannel(channelInfo, config,
[=](const zim::ZIMCommunityChannelFullInfo &channelFullInfo,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 创建成功
}
});
示例代码
const channelInfo: ZIMCommunityChannelInfo = {
channelID: 'channel_001',
channelName: '公告频道', //最大长度300字符,可配置
channelAvatarUrl: 'https://example.com/channel_avatar.png', //最大长度100字符,可配置
communityID: communityID,
};
const config: ZIMCommunityChannelCreateConfig = {
channelNotice: '这是频道公告', //最大长度500字符,可配置
channelAttributes: { type: 'announcement' },
};
zim.createCommunityChannel(channelInfo, config)
.then((result: ZIMCommunityChannelCreatedResult) => {
// result.channelFullInfo 包含频道完整信息
})
.catch((err: ZIMError) => {
// 创建失败
});
const channelInfo: ZIMCommunityChannelInfo = {
channelID: 'channel_001',
channelName: '公告频道', //最大长度300字符,可配置
channelAvatarUrl: 'https://example.com/channel_avatar.png', //最大长度100字符,可配置
communityID: communityID,
};
const config: ZIMCommunityChannelCreateConfig = {
channelNotice: '这是频道公告', //最大长度500字符,可配置
channelAttributes: { type: 'announcement' },
};
zim.createCommunityChannel(channelInfo, config)
.then((result: ZIMCommunityChannelCreatedResult) => {
// result.channelFullInfo 包含频道完整信息
})
.catch((err: ZIMError) => {
// 创建失败
});
示例代码
ZIMCommunityChannelInfo channelInfo = ZIMCommunityChannelInfo()
..channelID = 'channel_001'
..channelName = '公告频道' //最大长度300字符,可配置
..channelAvatarUrl = 'https://example.com/channel_avatar.png' //最大长度100字符,可配置
..communityID = communityID;
ZIMCommunityChannelCreateConfig config = ZIMCommunityChannelCreateConfig()
..channelNotice = '这是频道公告' //最大长度500字符,可配置
..channelAttributes = {'type': 'announcement'};
try {
ZIMCommunityChannelCreatedResult result =
await ZIM.getInstance()!.createCommunityChannel(channelInfo, config);
// result.channelFullInfo 包含频道完整信息
} on PlatformException catch (onError) {
// 创建失败
}
ZIMCommunityChannelInfo channelInfo = ZIMCommunityChannelInfo()
..channelID = 'channel_001'
..channelName = '公告频道' //最大长度300字符,可配置
..channelAvatarUrl = 'https://example.com/channel_avatar.png' //最大长度100字符,可配置
..communityID = communityID;
ZIMCommunityChannelCreateConfig config = ZIMCommunityChannelCreateConfig()
..channelNotice = '这是频道公告' //最大长度500字符,可配置
..channelAttributes = {'type': 'announcement'};
try {
ZIMCommunityChannelCreatedResult result =
await ZIM.getInstance()!.createCommunityChannel(channelInfo, config);
// result.channelFullInfo 包含频道完整信息
} on PlatformException catch (onError) {
// 创建失败
}
解散频道
调用 dismissCommunityChannel 接口解散指定社群中的频道,频道解散后所有成员将无法再访问该频道。
示例代码
zim.dismissCommunityChannel(channelID, communityID, new ZIMCommunityChannelDismissedCallback() {
@Override
public void onCommunityChannelDismissed(String communityID, String channelID, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 解散成功
}
}
});
zim.dismissCommunityChannel(channelID, communityID, new ZIMCommunityChannelDismissedCallback() {
@Override
public void onCommunityChannelDismissed(String communityID, String channelID, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 解散成功
}
}
});
示例代码
[zim dismissCommunityChannel:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 解散成功
}
}];
[zim dismissCommunityChannel:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 解散成功
}
}];
示例代码
zim_->dismissCommunityChannel(channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 解散成功
}
});
zim_->dismissCommunityChannel(channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 解散成功
}
});
示例代码
zim.dismissCommunityChannel(channelID, communityID)
.then((result: ZIMCommunityChannelDismissedResult) => {
// 解散成功
})
.catch((err: ZIMError) => {
// 解散失败
});
zim.dismissCommunityChannel(channelID, communityID)
.then((result: ZIMCommunityChannelDismissedResult) => {
// 解散成功
})
.catch((err: ZIMError) => {
// 解散失败
});
示例代码
try {
await ZIM.getInstance()!.dismissCommunityChannel(channelID, communityID);
// 解散成功
} on PlatformException catch (onError) {
// 解散失败
}
try {
await ZIM.getInstance()!.dismissCommunityChannel(channelID, communityID);
// 解散成功
} on PlatformException catch (onError) {
// 解散失败
}
更新频道资料
社群所有者和管理员可以更新频道的名称、头像和公告。
更新频道名称
调用 updateCommunityChannelName 接口更新频道名称。频道名称最大长度300字符,可配置。
示例代码
zim.updateCommunityChannelName("新的频道名称", channelID, communityID,
new ZIMCommunityChannelNameUpdatedCallback() {
@Override
public void onCommunityChannelNameUpdated(String communityID, String channelID, String channelName, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 更新成功
}
}
});
zim.updateCommunityChannelName("新的频道名称", channelID, communityID,
new ZIMCommunityChannelNameUpdatedCallback() {
@Override
public void onCommunityChannelNameUpdated(String communityID, String channelID, String channelName, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 更新成功
}
}
});
示例代码
[zim updateCommunityChannelName:@"新的频道名称" channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSString * _Nonnull channelName, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 更新成功
}
}];
[zim updateCommunityChannelName:@"新的频道名称" channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSString * _Nonnull channelName, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 更新成功
}
}];
示例代码
zim_->updateCommunityChannelName("新的频道名称", channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const std::string &channelName, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 更新成功
}
});
zim_->updateCommunityChannelName("新的频道名称", channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const std::string &channelName, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 更新成功
}
});
示例代码
zim.updateCommunityChannelName('新的频道名称', channelID, communityID)
.then((result: ZIMCommunityChannelNameUpdatedResult) => {
// 更新成功
})
.catch((err: ZIMError) => {
// 更新失败
});
zim.updateCommunityChannelName('新的频道名称', channelID, communityID)
.then((result: ZIMCommunityChannelNameUpdatedResult) => {
// 更新成功
})
.catch((err: ZIMError) => {
// 更新失败
});
示例代码
try {
await ZIM.getInstance()!
.updateCommunityChannelName('新的频道名称', channelID, communityID);
// 更新成功
} on PlatformException catch (onError) {
// 更新失败
}
try {
await ZIM.getInstance()!
.updateCommunityChannelName('新的频道名称', channelID, communityID);
// 更新成功
} on PlatformException catch (onError) {
// 更新失败
}
更新频道头像
调用 updateCommunityChannelAvatarUrl 接口更新频道头像。频道头像最大长度100字符,可配置。
示例代码
zim.updateCommunityChannelAvatarUrl("https://example.com/new_channel_avatar.png",
channelID, communityID,
new ZIMCommunityChannelAvatarUrlUpdatedCallback() {
@Override
public void onCommunityChannelAvatarUrlUpdated(String communityID, String channelID, String channelAvatarUrl, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 更新成功
}
}
});
zim.updateCommunityChannelAvatarUrl("https://example.com/new_channel_avatar.png",
channelID, communityID,
new ZIMCommunityChannelAvatarUrlUpdatedCallback() {
@Override
public void onCommunityChannelAvatarUrlUpdated(String communityID, String channelID, String channelAvatarUrl, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 更新成功
}
}
});
示例代码
[zim updateCommunityChannelAvatarUrl:@"https://example.com/new_channel_avatar.png" channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSString * _Nonnull channelAvatarUrl, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 更新成功
}
}];
[zim updateCommunityChannelAvatarUrl:@"https://example.com/new_channel_avatar.png" channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSString * _Nonnull channelAvatarUrl, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 更新成功
}
}];
示例代码
zim_->updateCommunityChannelAvatarUrl("https://example.com/new_channel_avatar.png",
channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const std::string &channelAvatarUrl, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 更新成功
}
});
zim_->updateCommunityChannelAvatarUrl("https://example.com/new_channel_avatar.png",
channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const std::string &channelAvatarUrl, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 更新成功
}
});
示例代码
zim.updateCommunityChannelAvatarUrl('https://example.com/new_channel_avatar.png', channelID, communityID)
.then((result: ZIMCommunityChannelAvatarUrlUpdatedResult) => {
// 更新成功
})
.catch((err: ZIMError) => {
// 更新失败
});
zim.updateCommunityChannelAvatarUrl('https://example.com/new_channel_avatar.png', channelID, communityID)
.then((result: ZIMCommunityChannelAvatarUrlUpdatedResult) => {
// 更新成功
})
.catch((err: ZIMError) => {
// 更新失败
});
示例代码
try {
await ZIM.getInstance()!.updateCommunityChannelAvatarUrl(
'https://example.com/new_channel_avatar.png', channelID, communityID);
// 更新成功
} on PlatformException catch (onError) {
// 更新失败
}
try {
await ZIM.getInstance()!.updateCommunityChannelAvatarUrl(
'https://example.com/new_channel_avatar.png', channelID, communityID);
// 更新成功
} on PlatformException catch (onError) {
// 更新失败
}
更新频道公告
调用 updateCommunityChannelNotice 接口更新频道公告内容。频道公告最大长度500字符,可配置。
示例代码
zim.updateCommunityChannelNotice("新的频道公告内容", channelID, communityID,
new ZIMCommunityChannelNoticeUpdatedCallback() {
@Override
public void onCommunityChannelNoticeUpdated(String communityID, String channelID, String channelNotice, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 更新成功
}
}
});
zim.updateCommunityChannelNotice("新的频道公告内容", channelID, communityID,
new ZIMCommunityChannelNoticeUpdatedCallback() {
@Override
public void onCommunityChannelNoticeUpdated(String communityID, String channelID, String channelNotice, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 更新成功
}
}
});
示例代码
[zim updateCommunityChannelNotice:@"新的频道公告内容" channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSString * _Nonnull channelNotice, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 更新成功
}
}];
[zim updateCommunityChannelNotice:@"新的频道公告内容" channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSString * _Nonnull channelNotice, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 更新成功
}
}];
示例代码
zim_->updateCommunityChannelNotice("新的频道公告内容", channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const std::string &channelNotice, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 更新成功
}
});
zim_->updateCommunityChannelNotice("新的频道公告内容", channelID, communityID,
[=](const std::string &communityID, const std::string &channelID,
const std::string &channelNotice, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 更新成功
}
});
示例代码
zim.updateCommunityChannelNotice('新的频道公告内容', channelID, communityID)
.then((result: ZIMCommunityChannelNoticeUpdatedResult) => {
// 更新成功
})
.catch((err: ZIMError) => {
// 更新失败
});
zim.updateCommunityChannelNotice('新的频道公告内容', channelID, communityID)
.then((result: ZIMCommunityChannelNoticeUpdatedResult) => {
// 更新成功
})
.catch((err: ZIMError) => {
// 更新失败
});
示例代码
try {
await ZIM.getInstance()!
.updateCommunityChannelNotice('新的频道公告内容', channelID, communityID);
// 更新成功
} on PlatformException catch (onError) {
// 更新失败
}
try {
await ZIM.getInstance()!
.updateCommunityChannelNotice('新的频道公告内容', channelID, communityID);
// 更新成功
} on PlatformException catch (onError) {
// 更新失败
}
设置频道属性
频道属性以键值对形式存储,可用于扩展频道的自定义信息。
设置属性
调用 setCommunityChannelAttributes 接口,批量设置频道自定义属性。操作失败的键名将通过 errorKeys 返回。
示例代码
HashMap<String, String> channelAttributes = new HashMap<>();
channelAttributes.put("key1", "value1");
channelAttributes.put("key2", "value2");
zim.setCommunityChannelAttributes(channelAttributes, channelID, communityID,
new ZIMCommunityChannelAttributesOperatedCallback() {
@Override
public void onCommunityChannelAttributesOperated(String communityID, String channelID, ArrayList<String> errorKeys, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 设置成功
}
}
});
HashMap<String, String> channelAttributes = new HashMap<>();
channelAttributes.put("key1", "value1");
channelAttributes.put("key2", "value2");
zim.setCommunityChannelAttributes(channelAttributes, channelID, communityID,
new ZIMCommunityChannelAttributesOperatedCallback() {
@Override
public void onCommunityChannelAttributesOperated(String communityID, String channelID, ArrayList<String> errorKeys, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 设置成功
}
}
});
示例代码
NSDictionary<NSString *, NSString *> *channelAttributes = @{@"key1": @"value1", @"key2": @"value2"};
[zim setCommunityChannelAttributes:channelAttributes channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSArray<NSString *> * _Nonnull errorKeys, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 设置成功
}
}];
NSDictionary<NSString *, NSString *> *channelAttributes = @{@"key1": @"value1", @"key2": @"value2"};
[zim setCommunityChannelAttributes:channelAttributes channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSArray<NSString *> * _Nonnull errorKeys, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 设置成功
}
}];
示例代码
std::unordered_map<std::string, std::string> channelAttributes;
channelAttributes["key1"] = "value1";
channelAttributes["key2"] = "value2";
zim_->setCommunityChannelAttributes(channelAttributes, channelID, communityID,
[=](const std::string &communityID,
const std::string &channelID,
const std::vector<std::string> &errorKeys,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 设置成功
}
});
std::unordered_map<std::string, std::string> channelAttributes;
channelAttributes["key1"] = "value1";
channelAttributes["key2"] = "value2";
zim_->setCommunityChannelAttributes(channelAttributes, channelID, communityID,
[=](const std::string &communityID,
const std::string &channelID,
const std::vector<std::string> &errorKeys,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 设置成功
}
});
示例代码
const channelAttributes: Record<string, string> = { key1: 'value1', key2: 'value2' };
zim.setCommunityChannelAttributes(channelAttributes, channelID, communityID)
.then((result: ZIMCommunityChannelAttributesOperatedResult) => {
// result.errorKeys 列出操作失败的键
})
.catch((err: ZIMError) => {
// 操作失败
});
const channelAttributes: Record<string, string> = { key1: 'value1', key2: 'value2' };
zim.setCommunityChannelAttributes(channelAttributes, channelID, communityID)
.then((result: ZIMCommunityChannelAttributesOperatedResult) => {
// result.errorKeys 列出操作失败的键
})
.catch((err: ZIMError) => {
// 操作失败
});
示例代码
Map<String, String> channelAttributes = {'key1': 'value1', 'key2': 'value2'};
try {
ZIMCommunityChannelAttributesOperatedResult result =
await ZIM.getInstance()!
.setCommunityChannelAttributes(channelAttributes, channelID, communityID);
// result.errorKeys 列出失败的键
} on PlatformException catch (onError) {
// 操作失败
}
Map<String, String> channelAttributes = {'key1': 'value1', 'key2': 'value2'};
try {
ZIMCommunityChannelAttributesOperatedResult result =
await ZIM.getInstance()!
.setCommunityChannelAttributes(channelAttributes, channelID, communityID);
// result.errorKeys 列出失败的键
} on PlatformException catch (onError) {
// 操作失败
}
删除属性
调用 deleteCommunityChannelAttributes 接口,按键名批量删除频道属性。
示例代码
ArrayList<String> keys = new ArrayList<>();
keys.add("key1");
keys.add("key2");
zim.deleteCommunityChannelAttributes(keys, channelID, communityID,
new ZIMCommunityChannelAttributesOperatedCallback() {
@Override
public void onCommunityChannelAttributesOperated(String communityID, String channelID, ArrayList<String> errorKeys, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 删除成功
}
}
});
ArrayList<String> keys = new ArrayList<>();
keys.add("key1");
keys.add("key2");
zim.deleteCommunityChannelAttributes(keys, channelID, communityID,
new ZIMCommunityChannelAttributesOperatedCallback() {
@Override
public void onCommunityChannelAttributesOperated(String communityID, String channelID, ArrayList<String> errorKeys, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 删除成功
}
}
});
示例代码
NSArray<NSString *> *keys = @[@"key1", @"key2"];
[zim deleteCommunityChannelAttributes:keys channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSArray<NSString *> * _Nonnull errorKeys, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 删除成功
}
}];
NSArray<NSString *> *keys = @[@"key1", @"key2"];
[zim deleteCommunityChannelAttributes:keys channelID:channelID communityID:communityID callback:^(NSString * _Nonnull communityID, NSString * _Nonnull channelID, NSArray<NSString *> * _Nonnull errorKeys, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 删除成功
}
}];
示例代码
std::vector<std::string> keys = {"key1", "key2"};
zim_->deleteCommunityChannelAttributes(keys, channelID, communityID,
[=](const std::string &communityID,
const std::string &channelID,
const std::vector<std::string> &errorKeys,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 删除成功
}
});
std::vector<std::string> keys = {"key1", "key2"};
zim_->deleteCommunityChannelAttributes(keys, channelID, communityID,
[=](const std::string &communityID,
const std::string &channelID,
const std::vector<std::string> &errorKeys,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 删除成功
}
});
示例代码
const keys = ['key1', 'key2'];
zim.deleteCommunityChannelAttributes(keys, channelID, communityID)
.then((result: ZIMCommunityChannelAttributesOperatedResult) => {
// 删除成功
})
.catch((err: ZIMError) => {
// 删除失败
});
const keys = ['key1', 'key2'];
zim.deleteCommunityChannelAttributes(keys, channelID, communityID)
.then((result: ZIMCommunityChannelAttributesOperatedResult) => {
// 删除成功
})
.catch((err: ZIMError) => {
// 删除失败
});
示例代码
List<String> keys = ['key1', 'key2'];
try {
await ZIM.getInstance()!
.deleteCommunityChannelAttributes(keys, channelID, communityID);
// 删除成功
} on PlatformException catch (onError) {
// 删除失败
}
List<String> keys = ['key1', 'key2'];
try {
await ZIM.getInstance()!
.deleteCommunityChannelAttributes(keys, channelID, communityID);
// 删除成功
} on PlatformException catch (onError) {
// 删除失败
}
查询频道信息
调用 queryCommunityChannelsInfo 接口,批量查询指定频道的完整信息,包括频道名称、头像、公告、禁言状态等。查询失败的频道 ID 将通过 errorChannelIDs 返回。
示例代码
ArrayList<String> channelIDs = new ArrayList<>();
channelIDs.add("channel_001");
channelIDs.add("channel_002");
zim.queryCommunityChannelsInfo(channelIDs, communityID,
new ZIMCommunityChannelsInfoQueriedCallback() {
@Override
public void onCommunityChannelsInfoQueried(String communityID, ArrayList<ZIMCommunityChannelFullInfo> channelInfos, ArrayList<String> errorChannelIDs, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// channelInfos 包含各频道的完整信息
}
}
});
ArrayList<String> channelIDs = new ArrayList<>();
channelIDs.add("channel_001");
channelIDs.add("channel_002");
zim.queryCommunityChannelsInfo(channelIDs, communityID,
new ZIMCommunityChannelsInfoQueriedCallback() {
@Override
public void onCommunityChannelsInfoQueried(String communityID, ArrayList<ZIMCommunityChannelFullInfo> channelInfos, ArrayList<String> errorChannelIDs, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// channelInfos 包含各频道的完整信息
}
}
});
示例代码
NSArray<NSString *> *channelIDs = @[@"channel_001", @"channel_002"];
[zim queryCommunityChannelsInfoByChannelIDs:channelIDs communityID:communityID callback:^(NSString * _Nonnull communityID, NSArray<ZIMCommunityChannelFullInfo *> * _Nonnull channelInfos, NSArray<NSString *> * _Nonnull errorChannelIDs, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 查询成功
}
}];
NSArray<NSString *> *channelIDs = @[@"channel_001", @"channel_002"];
[zim queryCommunityChannelsInfoByChannelIDs:channelIDs communityID:communityID callback:^(NSString * _Nonnull communityID, NSArray<ZIMCommunityChannelFullInfo *> * _Nonnull channelInfos, NSArray<NSString *> * _Nonnull errorChannelIDs, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 查询成功
}
}];
示例代码
std::vector<std::string> channelIDs = {"channel_001", "channel_002"};
zim_->queryCommunityChannelsInfoByChannelIDs(channelIDs, communityID,
[=](const std::string &communityID,
const std::vector<zim::ZIMCommunityChannelFullInfo> &channelInfos,
const std::vector<std::string> &errorChannelIDs,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 查询成功
}
});
std::vector<std::string> channelIDs = {"channel_001", "channel_002"};
zim_->queryCommunityChannelsInfoByChannelIDs(channelIDs, communityID,
[=](const std::string &communityID,
const std::vector<zim::ZIMCommunityChannelFullInfo> &channelInfos,
const std::vector<std::string> &errorChannelIDs,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 查询成功
}
});
示例代码
const channelIDs = ['channel_001', 'channel_002'];
zim.queryCommunityChannelsInfo(channelIDs, communityID)
.then((result: ZIMCommunityChannelsInfoQueriedResult) => {
// result.channelInfos 包含各频道完整信息
})
.catch((err: ZIMError) => {
// 查询失败
});
const channelIDs = ['channel_001', 'channel_002'];
zim.queryCommunityChannelsInfo(channelIDs, communityID)
.then((result: ZIMCommunityChannelsInfoQueriedResult) => {
// result.channelInfos 包含各频道完整信息
})
.catch((err: ZIMError) => {
// 查询失败
});
示例代码
List<String> channelIDs = ['channel_001', 'channel_002'];
try {
ZIMCommunityChannelsInfoQueriedResult result =
await ZIM.getInstance()!.queryCommunityChannelsInfo(channelIDs, communityID);
// result.channelInfos 包含各频道完整信息
} on PlatformException catch (onError) {
// 查询失败
}
List<String> channelIDs = ['channel_001', 'channel_002'];
try {
ZIMCommunityChannelsInfoQueriedResult result =
await ZIM.getInstance()!.queryCommunityChannelsInfo(channelIDs, communityID);
// result.channelInfos 包含各频道完整信息
} on PlatformException catch (onError) {
// 查询失败
}
查询频道列表
调用 queryCommunityChannelList 接口,分页拉取指定社群中的所有频道列表。返回的频道对象 ZIMCommunityChannel 中的 conversationID 字段,即是后续收发消息时所需的会话 ID。
分页规则与查询社群列表一致:首次将 config.nextFlag 设为 0,后续将返回的 nextFlag 传入下次请求,直到返回 0 为止。count 取值范围 1-100,推荐值 20。
示例代码
ZIMCommunityChannelListQueryConfig config = new ZIMCommunityChannelListQueryConfig();
config.setNextFlag(0);
zim.queryCommunityChannelList(communityID, 100, config,
new ZIMCommunityChannelListQueriedCallback() {
@Override
public void onCommunityChannelListQueried(String communityID, ArrayList<ZIMCommunityChannel> channelList, long nextFlag, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
for (ZIMCommunityChannel channel : channelList) {
// channel.getBaseInfo().getChannelID():频道 ID
// channel.getBaseInfo().getChannelName():频道名称
// channel.getConversationID():用于收发消息的会话 ID
}
}
}
});
ZIMCommunityChannelListQueryConfig config = new ZIMCommunityChannelListQueryConfig();
config.setNextFlag(0);
zim.queryCommunityChannelList(communityID, 100, config,
new ZIMCommunityChannelListQueriedCallback() {
@Override
public void onCommunityChannelListQueried(String communityID, ArrayList<ZIMCommunityChannel> channelList, long nextFlag, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
for (ZIMCommunityChannel channel : channelList) {
// channel.getBaseInfo().getChannelID():频道 ID
// channel.getBaseInfo().getChannelName():频道名称
// channel.getConversationID():用于收发消息的会话 ID
}
}
}
});
示例代码
ZIMCommunityChannelListQueryConfig *config = [[ZIMCommunityChannelListQueryConfig alloc] init];
config.nextFlag = 0;
[zim queryCommunityChannelList:communityID count:100 config:config callback:^(NSString * _Nonnull communityID, NSArray<ZIMCommunityChannel *> * _Nonnull channelList, long long nextFlag, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 查询成功,channelList 为频道列表
}
}];
ZIMCommunityChannelListQueryConfig *config = [[ZIMCommunityChannelListQueryConfig alloc] init];
config.nextFlag = 0;
[zim queryCommunityChannelList:communityID count:100 config:config callback:^(NSString * _Nonnull communityID, NSArray<ZIMCommunityChannel *> * _Nonnull channelList, long long nextFlag, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 查询成功,channelList 为频道列表
}
}];
示例代码
zim::ZIMCommunityChannelListQueryConfig config;
config.nextFlag = 0;
zim_->queryCommunityChannelList(communityID, 100, config,
[=](const std::string &communityID,
const std::vector<zim::ZIMCommunityChannel> &channelList,
long long nextFlag,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 查询成功
}
});
zim::ZIMCommunityChannelListQueryConfig config;
config.nextFlag = 0;
zim_->queryCommunityChannelList(communityID, 100, config,
[=](const std::string &communityID,
const std::vector<zim::ZIMCommunityChannel> &channelList,
long long nextFlag,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 查询成功
}
});
示例代码
const config: ZIMCommunityChannelListQueryConfig = { nextFlag: 0 };
zim.queryCommunityChannelList(communityID, 100, config)
.then((result: ZIMCommunityChannelListQueriedResult) => {
const { channelList, nextFlag } = result;
// channel.conversationID 用于收发消息
})
.catch((err: ZIMError) => {
// 查询失败
});
const config: ZIMCommunityChannelListQueryConfig = { nextFlag: 0 };
zim.queryCommunityChannelList(communityID, 100, config)
.then((result: ZIMCommunityChannelListQueriedResult) => {
const { channelList, nextFlag } = result;
// channel.conversationID 用于收发消息
})
.catch((err: ZIMError) => {
// 查询失败
});
示例代码
ZIMCommunityChannelListQueryConfig config =
ZIMCommunityChannelListQueryConfig()..nextFlag = 0;
try {
ZIMCommunityChannelListQueriedResult result =
await ZIM.getInstance()!.queryCommunityChannelList(communityID, 100, config);
// result.channelList 为频道列表
} on PlatformException catch (onError) {
// 查询失败
}
ZIMCommunityChannelListQueryConfig config =
ZIMCommunityChannelListQueryConfig()..nextFlag = 0;
try {
ZIMCommunityChannelListQueriedResult result =
await ZIM.getInstance()!.queryCommunityChannelList(communityID, 100, config);
// result.channelList 为频道列表
} on PlatformException catch (onError) {
// 查询失败
}
设置频道禁言
调用 muteCommunityChannels 接口,批量设置指定频道的禁言状态。禁言配置通过 ZIMCommunityChannelMuteConfig 传入。
channelIDs 和 communityID 是接口方法的直接参数,非 config 配置字段。
| 配置字段 | 说明 |
|---|
mode | 禁言范围。枚举值对照:NONE(0) = 不禁言、NORMAL(1) = 禁言普通成员、ALL(2) = 全员禁言、CUSTOM(3) = 自定义角色范围 |
duration | 禁言时长(秒),取值范围 1-2592001(约 30 天),或 -1 表示永久禁言 |
roles | 当 mode 为 CUSTOM 时,指定被禁言的角色列表 |
操作失败的频道 ID 将通过 errorChannelIDs 返回。详细操作请参考 社群禁言。
示例代码
ArrayList<String> channelIDs = new ArrayList<>();
channelIDs.add("channel_001");
channelIDs.add("channel_002");
ZIMCommunityChannelMuteConfig config = new ZIMCommunityChannelMuteConfig();
config.setDuration(3600); // 禁言 1 小时;-1 为永久禁言
config.setMode(ZIMCommunityChannelMuteMode.ALL); // 禁言所有人
// isMute = true 为禁言,false 为解除禁言
zim.muteCommunityChannels(true, channelIDs, communityID, config,
new ZIMCommunityChannelsMutedCallback() {
@Override
public void onCommunityChannelsMuted(String communityID, boolean isMute, ArrayList<String> errorChannelIDs, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 禁言设置成功
}
}
});
ArrayList<String> channelIDs = new ArrayList<>();
channelIDs.add("channel_001");
channelIDs.add("channel_002");
ZIMCommunityChannelMuteConfig config = new ZIMCommunityChannelMuteConfig();
config.setDuration(3600); // 禁言 1 小时;-1 为永久禁言
config.setMode(ZIMCommunityChannelMuteMode.ALL); // 禁言所有人
// isMute = true 为禁言,false 为解除禁言
zim.muteCommunityChannels(true, channelIDs, communityID, config,
new ZIMCommunityChannelsMutedCallback() {
@Override
public void onCommunityChannelsMuted(String communityID, boolean isMute, ArrayList<String> errorChannelIDs, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// 禁言设置成功
}
}
});
示例代码
NSArray<NSString *> *channelIDs = @[@"channel_001", @"channel_002"];
ZIMCommunityChannelMuteConfig *config = [[ZIMCommunityChannelMuteConfig alloc] init];
config.duration = 3600;
config.mode = ZIMCommunityChannelMuteModeAll;
[zim muteCommunityChannels:YES channelIDs:channelIDs communityID:communityID config:config callback:^(NSString * _Nonnull communityID, BOOL isMute, NSArray<NSString *> * _Nonnull errorChannelIDs, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 禁言设置成功
}
}];
NSArray<NSString *> *channelIDs = @[@"channel_001", @"channel_002"];
ZIMCommunityChannelMuteConfig *config = [[ZIMCommunityChannelMuteConfig alloc] init];
config.duration = 3600;
config.mode = ZIMCommunityChannelMuteModeAll;
[zim muteCommunityChannels:YES channelIDs:channelIDs communityID:communityID config:config callback:^(NSString * _Nonnull communityID, BOOL isMute, NSArray<NSString *> * _Nonnull errorChannelIDs, ZIMError * _Nonnull errorInfo) {
if (errorInfo.code == ZIMErrorCodenoneSuccess) {
// 禁言设置成功
}
}];
示例代码
std::vector<std::string> channelIDs = {"channel_001", "channel_002"};
zim::ZIMCommunityChannelMuteConfig config;
config.duration = 3600;
config.mode = zim::ZIM_COMMUNITY_CHANNEL_MUTE_MODE_ALL;
zim_->muteCommunityChannels(true, channelIDs, communityID, config,
[=](const std::string &communityID,
bool isMute,
const std::vector<std::string> &errorChannelIDs,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 禁言设置成功
}
});
std::vector<std::string> channelIDs = {"channel_001", "channel_002"};
zim::ZIMCommunityChannelMuteConfig config;
config.duration = 3600;
config.mode = zim::ZIM_COMMUNITY_CHANNEL_MUTE_MODE_ALL;
zim_->muteCommunityChannels(true, channelIDs, communityID, config,
[=](const std::string &communityID,
bool isMute,
const std::vector<std::string> &errorChannelIDs,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIM_ERROR_CODE_SUCCESS) {
// 禁言设置成功
}
});
示例代码
const channelIDs = ['channel_001', 'channel_002'];
const config: ZIMCommunityChannelMuteConfig = {
duration: 3600,
mode: 2, // 2 = ALL,全员禁言
};
zim.muteCommunityChannels(true, channelIDs, communityID, config)
.then((result: ZIMCommunityChannelsMutedResult) => {
// result.errorChannelIDs 列出失败的频道
})
.catch((err: ZIMError) => {
// 操作失败
});
const channelIDs = ['channel_001', 'channel_002'];
const config: ZIMCommunityChannelMuteConfig = {
duration: 3600,
mode: 2, // 2 = ALL,全员禁言
};
zim.muteCommunityChannels(true, channelIDs, communityID, config)
.then((result: ZIMCommunityChannelsMutedResult) => {
// result.errorChannelIDs 列出失败的频道
})
.catch((err: ZIMError) => {
// 操作失败
});
示例代码
List<String> channelIDs = ['channel_001', 'channel_002'];
ZIMCommunityChannelMuteConfig config = ZIMCommunityChannelMuteConfig()
..duration = 3600
..mode = ZIMCommunityChannelMuteMode.all;
try {
ZIMCommunityChannelsMutedResult result =
await ZIM.getInstance()!
.muteCommunityChannels(true, channelIDs, communityID, config);
// result.errorChannelIDs 列出失败的频道
} on PlatformException catch (onError) {
// 操作失败
}
List<String> channelIDs = ['channel_001', 'channel_002'];
ZIMCommunityChannelMuteConfig config = ZIMCommunityChannelMuteConfig()
..duration = 3600
..mode = ZIMCommunityChannelMuteMode.all;
try {
ZIMCommunityChannelsMutedResult result =
await ZIM.getInstance()!
.muteCommunityChannels(true, channelIDs, communityID, config);
// result.errorChannelIDs 列出失败的频道
} on PlatformException catch (onError) {
// 操作失败
}
监听频道变更
频道列表变更
当社群中频道被创建或解散,导致频道列表发生变化时,SDK 会触发 onCommunityChannelListChanged 回调。changeInfoList 包含各变更频道的变更类型及频道信息。
示例代码
zim.setEventHandler(new ZIMEventHandler() {
@Override
public void onCommunityChannelListChanged(ZIM zim, ZIMCommunityChannelListChangedEventResult result) {
String communityID = result.getCommunityID();
for (ZIMCommunityChannelChangeInfo changeInfo : result.getChangeInfoList()) {
// changeInfo.action:变更类型(创建 / 解散)
// changeInfo.channel:变更的频道信息
}
}
});
zim.setEventHandler(new ZIMEventHandler() {
@Override
public void onCommunityChannelListChanged(ZIM zim, ZIMCommunityChannelListChangedEventResult result) {
String communityID = result.getCommunityID();
for (ZIMCommunityChannelChangeInfo changeInfo : result.getChangeInfoList()) {
// changeInfo.action:变更类型(创建 / 解散)
// changeInfo.channel:变更的频道信息
}
}
});
示例代码
- (void)zim:(ZIM *)zim communityChannelListChangedWithResult:(ZIMCommunityChannelListChangedEventResult *)result {
NSString *communityID = result.communityID;
for (ZIMCommunityChannelChangeInfo *changeInfo in result.changeInfoList) {
// changeInfo.action:变更类型
// changeInfo.channel:变更的频道信息
}
}
- (void)zim:(ZIM *)zim communityChannelListChangedWithResult:(ZIMCommunityChannelListChangedEventResult *)result {
NSString *communityID = result.communityID;
for (ZIMCommunityChannelChangeInfo *changeInfo in result.changeInfoList) {
// changeInfo.action:变更类型
// changeInfo.channel:变更的频道信息
}
}
示例代码
void onCommunityChannelListChanged(zim::ZIM *zim,
const zim::ZIMCommunityChannelListChangedEventResult &result) override {
std::string communityID = result.communityID;
for (const auto &changeInfo : result.changeInfoList) {
// changeInfo 包含频道变更信息
}
}
void onCommunityChannelListChanged(zim::ZIM *zim,
const zim::ZIMCommunityChannelListChangedEventResult &result) override {
std::string communityID = result.communityID;
for (const auto &changeInfo : result.changeInfoList) {
// changeInfo 包含频道变更信息
}
}
示例代码
zim.on('communityChannelListChanged', (zim, result) => {
const communityID = result.communityID;
for (const changeInfo of result.changeInfoList) {
// changeInfo.action:变更类型
// changeInfo.channel:变更的频道信息
}
});
zim.on('communityChannelListChanged', (zim, result) => {
const communityID = result.communityID;
for (const changeInfo of result.changeInfoList) {
// changeInfo.action:变更类型
// changeInfo.channel:变更的频道信息
}
});
示例代码
ZIMEventHandler.onCommunityChannelListChanged =
(ZIM zim, ZIMCommunityChannelListChangedEventResult result) {
for (final changeInfo in result.changeInfoList) {
// changeInfo 包含频道变更信息
}
};
ZIMEventHandler.onCommunityChannelListChanged =
(ZIM zim, ZIMCommunityChannelListChangedEventResult result) {
for (final changeInfo in result.changeInfoList) {
// changeInfo 包含频道变更信息
}
};
频道信息更新
当频道资料(名称、头像、公告、属性、禁言状态等)发生变化时,SDK 会触发 onCommunityChannelInfoUpdated 回调。updateInfoList 包含变更后的频道完整信息。
示例代码
zim.setEventHandler(new ZIMEventHandler() {
@Override
public void onCommunityChannelInfoUpdated(ZIM zim, ZIMCommunityChannelInfoUpdatedEventResult result) {
String communityID = result.getCommunityID();
for (ZIMCommunityChannelFullInfoUpdateInfo updateInfo : result.getUpdateInfoList()) {
// updateInfo.channelInfo:更新后的频道完整信息
}
}
});
zim.setEventHandler(new ZIMEventHandler() {
@Override
public void onCommunityChannelInfoUpdated(ZIM zim, ZIMCommunityChannelInfoUpdatedEventResult result) {
String communityID = result.getCommunityID();
for (ZIMCommunityChannelFullInfoUpdateInfo updateInfo : result.getUpdateInfoList()) {
// updateInfo.channelInfo:更新后的频道完整信息
}
}
});
示例代码
- (void)zim:(ZIM *)zim communityChannelInfoUpdatedWithResult:(ZIMCommunityChannelInfoUpdatedEventResult *)result {
NSString *communityID = result.communityID;
for (ZIMCommunityChannelFullInfoUpdateInfo *updateInfo in result.updateInfoList) {
// updateInfo.channelInfo:更新后的频道完整信息
}
}
- (void)zim:(ZIM *)zim communityChannelInfoUpdatedWithResult:(ZIMCommunityChannelInfoUpdatedEventResult *)result {
NSString *communityID = result.communityID;
for (ZIMCommunityChannelFullInfoUpdateInfo *updateInfo in result.updateInfoList) {
// updateInfo.channelInfo:更新后的频道完整信息
}
}
示例代码
void onCommunityChannelInfoUpdated(zim::ZIM *zim,
const zim::ZIMCommunityChannelInfoUpdatedEventResult &result) override {
std::string communityID = result.communityID;
for (const auto &updateInfo : result.updateInfoList) {
// updateInfo 包含更新后的频道信息
}
}
void onCommunityChannelInfoUpdated(zim::ZIM *zim,
const zim::ZIMCommunityChannelInfoUpdatedEventResult &result) override {
std::string communityID = result.communityID;
for (const auto &updateInfo : result.updateInfoList) {
// updateInfo 包含更新后的频道信息
}
}
示例代码
zim.on('communityChannelInfoUpdated', (zim, result) => {
const communityID = result.communityID;
for (const updateInfo of result.updateInfoList) {
// updateInfo.channelInfo:更新后的频道完整信息
}
});
zim.on('communityChannelInfoUpdated', (zim, result) => {
const communityID = result.communityID;
for (const updateInfo of result.updateInfoList) {
// updateInfo.channelInfo:更新后的频道完整信息
}
});
示例代码
ZIMEventHandler.onCommunityChannelInfoUpdated =
(ZIM zim, ZIMCommunityChannelInfoUpdatedEventResult result) {
for (final updateInfo in result.updateInfoList) {
// updateInfo 包含更新后的频道信息
}
};
ZIMEventHandler.onCommunityChannelInfoUpdated =
(ZIM zim, ZIMCommunityChannelInfoUpdatedEventResult result) {
for (final updateInfo in result.updateInfoList) {
// updateInfo 包含更新后的频道信息
}
};
相关参考