Each Community channel corresponds to a conversation of type COMMUNITY_CHANNEL. Using the channel's conversationID, you can operate on channel conversations through ZIM's standard conversation management APIs, including:
Getting the channel list (including the conversation ID)
Clearing the unread message count of a channel
Setting/clearing the draft of a channel conversation
Configuring Do Not Disturb for a channel conversation
Listening for channel conversation changes
Prerequisites
Please refer to Send and receive messages to complete ZIM SDK integration, initialization, and user login.
The Community feature requires ZIM SDK 3.0.0 or later.
The Community feature is part of the Premium plan. Please contact ZEGOCLOUD Technical Support to enable it before use.
The Token generation for the Community feature is consistent with other ZIM features, and no additional permission declarations are required.
Note
The conversationID of a channel conversation is different from the channel's channelID. When sending messages and managing conversations, please use the conversationID field obtained from the ZIMCommunityChannel object.
Warning
Do not mistakenly use channelID as conversationID. When sending messages and performing conversation management operations, you must use the conversationID obtained from the channel object (ZIMCommunityChannel), not channelID.
Get the channel list
Before managing channel conversations, you need to call the queryCommunityChannelList API to get the channel list and obtain the conversationID from the returned ZIMCommunityChannel object for subsequent conversation operations.
Pagination rule: Set config.nextFlag to 0 for the first request, pass the returned nextFlag to the next request, and continue until 0 is returned.
Example code
import im.zego.zim.ZIM;
import im.zego.zim.callback.ZIMCommunityChannelListQueriedCallback;
import im.zego.zim.entity.ZIMCommunityChannel;
import im.zego.zim.entity.ZIMCommunityChannelListQueryConfig;
import im.zego.zim.entity.ZIMError;
import im.zego.zim.enums.ZIMErrorCode;
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) {
String conversationID = channel.getConversationID(); // Used for subsequent conversation management
}
}
}
});
import im.zego.zim.ZIM;
import im.zego.zim.callback.ZIMCommunityChannelListQueriedCallback;
import im.zego.zim.entity.ZIMCommunityChannel;
import im.zego.zim.entity.ZIMCommunityChannelListQueryConfig;
import im.zego.zim.entity.ZIMError;
import im.zego.zim.enums.ZIMErrorCode;
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) {
String conversationID = channel.getConversationID(); // Used for subsequent conversation management
}
}
}
});
Example code
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) {
for (ZIMCommunityChannel *channel in channelList) {
NSString *conversationID = channel.conversationID; // Used for subsequent conversation management
}
}
}];
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) {
for (ZIMCommunityChannel *channel in channelList) {
NSString *conversationID = channel.conversationID; // Used for subsequent conversation management
}
}
}];
Example code
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) {
for (const auto &channel : channelList) {
std::string conversationID = channel.conversationID; // Used for subsequent conversation management
}
}
});
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) {
for (const auto &channel : channelList) {
std::string conversationID = channel.conversationID; // Used for subsequent conversation management
}
}
});
ZIMCommunityChannelListQueryConfig config =
ZIMCommunityChannelListQueryConfig()..nextFlag = 0;
try {
ZIMCommunityChannelListQueriedResult result =
await ZIM.getInstance()!.queryCommunityChannelList(communityID, 100, config);
for (final channel in result.channelList) {
final conversationID = channel.conversationID; // Used for subsequent conversation management
}
} on PlatformException catch (onError) {
// Query failed
}
ZIMCommunityChannelListQueryConfig config =
ZIMCommunityChannelListQueryConfig()..nextFlag = 0;
try {
ZIMCommunityChannelListQueriedResult result =
await ZIM.getInstance()!.queryCommunityChannelList(communityID, 100, config);
for (final channel in result.channelList) {
final conversationID = channel.conversationID; // Used for subsequent conversation management
}
} on PlatformException catch (onError) {
// Query failed
}
Clear unread message count
Call the clearConversationUnreadMessageCount API to reset the unread message count of a specified channel conversation to zero. After successful clearing, the conversationChanged callback will be triggered to reflect the latest conversation state.
Example code
// conversationID comes from ZIMCommunityChannel.conversationID
String conversationID = channel.getConversationID();
ZIMConversationType conversationType = ZIMConversationType.COMMUNITY_CHANNEL;
zim.clearConversationUnreadMessageCount(conversationID, conversationType,
new ZIMConversationUnreadMessageCountClearedCallback() {
@Override
public void onConversationUnreadMessageCountCleared(String conversationID, ZIMConversationType conversationType, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// Unread count cleared
}
}
});
// conversationID comes from ZIMCommunityChannel.conversationID
String conversationID = channel.getConversationID();
ZIMConversationType conversationType = ZIMConversationType.COMMUNITY_CHANNEL;
zim.clearConversationUnreadMessageCount(conversationID, conversationType,
new ZIMConversationUnreadMessageCountClearedCallback() {
@Override
public void onConversationUnreadMessageCountCleared(String conversationID, ZIMConversationType conversationType, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// Unread count cleared
}
}
});
Call the setConversationDraft API to save draft content for a specified channel conversation, allowing the user to continue editing after leaving the channel. Draft content is stored locally only and will not be sent to other users.
Note
To clear the draft, simply pass an empty string for draft.
Call the setConversationNotificationStatus API to set the Do Not Disturb status for a specified channel conversation. When set to Do Not Disturb, the unread message count of that channel will no longer be added to the total unread count of the Community, and system push notifications will not be triggered.
Example code
String conversationID = channel.getConversationID();
ZIMConversationType conversationType = ZIMConversationType.COMMUNITY_CHANNEL;
// ZIMConversationNotificationStatus.DO_NOT_DISTURB = Do Not Disturb
// ZIMConversationNotificationStatus.NOTIFY = Normal notification
zim.setConversationNotificationStatus(
ZIMConversationNotificationStatus.DO_NOT_DISTURB,
conversationID,
conversationType,
new ZIMConversationNotificationStatusSetCallback() {
@Override
public void onConversationNotificationStatusSet(String conversationID, ZIMConversationType conversationType, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// Set successfully
}
}
});
String conversationID = channel.getConversationID();
ZIMConversationType conversationType = ZIMConversationType.COMMUNITY_CHANNEL;
// ZIMConversationNotificationStatus.DO_NOT_DISTURB = Do Not Disturb
// ZIMConversationNotificationStatus.NOTIFY = Normal notification
zim.setConversationNotificationStatus(
ZIMConversationNotificationStatus.DO_NOT_DISTURB,
conversationID,
conversationType,
new ZIMConversationNotificationStatusSetCallback() {
@Override
public void onConversationNotificationStatusSet(String conversationID, ZIMConversationType conversationType, ZIMError errorInfo) {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// Set successfully
}
}
});
When channels in a Community are created, disbanded, or their visible information changes, the channel list updates accordingly. The SDK notifies the developer through the onCommunityChannelListChanged callback. You can re-fetch the channel list in this callback to update the local conversationID mapping. For details, see Community channel management - Listen for channel list changes.
Note
Changes to channel conversations (such as unread count changes, draft updates, etc.) will also trigger the conversationChanged callback. For the complete usage of conversation change listening, refer to Get the conversation list.