Community mute
The current Community mute feature only supports muting operations on channels within a Community. Community-level global muting is not yet supported.
After a user logs in to the ZIM SDK, they can set the mute status of Community channels through muteCommunityChannels, supporting batch settings for multiple channels.
Prerequisites
- Please refer to Send and receive messages to complete ZIM SDK integration, initialization, and user login.
- Please refer to Token-based authentication to implement user authentication 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.
Feature description
- Supports batch setting the mute status for multiple channels. The mute configuration is specified through
ZIMCommunityChannelMuteConfig. config.modedetermines the mute scope:NONE(no mute, used to unmute),NORMAL(mute ordinary members),ALL(mute everyone including admins and group owners),CUSTOM(custom role scope, controlled byconfig.roles).config.durationspecifies the mute duration in seconds, with a range of 1-2592001 (approximately 30 days), or-1for permanent muting.
After successful setting, the result can be obtained through ZIMCommunityChannelsMutedCallback.
| Configuration field | Description |
|---|---|
mode | Mute scope: NONE(0) unmute all roles (used to unmute; isMute=true with mode=NONE is equivalent to canceling mute), NORMAL(1) mute ordinary members, ALL(2) mute all members, CUSTOM(3) custom role scope |
roles | Takes effect when mode is Custom, specifying the list of roles to be muted |
duration | Mute duration (seconds), 1-2592001 or -1 for permanent muting |
channelIDs and communityID are direct parameters of the API method, not config fields.
Mute mechanism description
Community supports two mute dimensions, which can take effect simultaneously:
| Dimension | API | Scope | Description |
|---|---|---|---|
| Channel mute | muteCommunityChannels | Channel level | Mute specified channels, with the mute role scope controlled by config.mode |
| Member mute | muteCommunityMembers | Member level | Mute specified members in specified channels (if left empty, applies to all channels) |
- When a member's channel is set to muted and the member has not been individually muted, the channel mute configuration takes precedence.
- When a member is individually muted, that member cannot send messages regardless of the channel's mute status.
- For details on member muting, see Community member management - Set member mute.
Example code
const channelIDs = ['channel_1', 'channel_2'];
const config: ZIMCommunityChannelMuteConfig = {
duration: 3600,
mode: 2, // "1: Normal" | "2: All" | "3: Custom"
// roles: [101, 102], // Pass in when mode = 'Custom'
};
zim.muteCommunityChannels(true, channelIDs, communityID, config)
.then((result: ZIMCommunityChannelsMutedResult) => {
// result.errorChannelIDs is the list of channel IDs that failed
})
.catch((err: ZIMError) => {
// Operation failed
});| Error code | Description | Recommendation |
|---|---|---|
| 6001004 | Community does not exist | Verify that the communityID is correct |
| 6001062 | Channel does not exist | Verify that the channelID is correct |
| 6001065 | Cannot disband the default channel | The default channel does not support disbanding |
| 6001007 | Community permission error | Verify that the current user is an admin or owner |
Query channel mute status
Call the queryCommunityChannelsInfo API to batch query the full information of specified channels, including the current mute status.
channelInfosreturns a list ofZIMCommunityChannelFullInfo, wheremuteInfocontains the channel mute information.errorChannelIDsreturns the list of channel IDs that failed the query.
| Result field | Description |
|---|---|
baseInfo | Basic channel information |
createTime | Channel creation time |
creatorUserID | User ID of the channel creator |
channelNotice | Channel notice |
channelAttributes | Channel attributes dictionary |
currentMemberCount | Current number of channel members |
muteInfo | Channel mute information, including mode, expiredTime, and roles |
muteInfo field description
| Field | Type | Description |
|---|---|---|
| mode | ZIMCommunityChannelMuteMode | Current mute mode: NONE(0), NORMAL(1), ALL(2), CUSTOM(3) |
| expiredTime | long | Mute expiration time (milliseconds); mute is automatically lifted after expiration |
| roles | ArrayList<Integer> | List of currently muted roles; only has a value when mode is CUSTOM |
const channelIDs = ['channel_1', 'channel_2'];
zim.queryCommunityChannelsInfo(channelIDs, communityID)
.then((result: ZIMCommunityChannelsInfoQueriedResult) => {
const { channelInfos } = result;
channelInfos.forEach((channelInfo) => {
const muteInfo = channelInfo.muteInfo;
// muteInfo.mode : Current channel mute mode
// muteInfo.expiredTime : Mute expiration time (milliseconds)
// muteInfo.roles : List of currently muted roles
});
})
.catch((err: ZIMError) => {
// Query failed
});Listen for channel mute change events
When channel information (name, avatar, notice, attributes, mute status, etc.) changes, the SDK triggers a channel information update callback. You can obtain the channelInfo.muteInfo from updateInfoList through this callback to determine the current mute mode and muted roles of a channel.
communityID: The Community ID that triggered the update.updateInfoList: The list of updated full channel information.channelInfo.muteInfo: Contains mute status information such asmode,expiredTime, androles.
Due to the large scale of Communities, the SDK may only push channel information change notifications to active users. If no push is received, you can proactively fetch the latest channel information through
queryCommunityChannelsInfo.
zim.on('communityChannelInfoUpdated', (zim, result) => {
const communityID = result.communityID;
result.updateInfoList.forEach((updateInfo) => {
const channelInfo = updateInfo.channelInfo;
const muteInfo = channelInfo.muteInfo;
// muteInfo.mode : Current channel mute mode
// muteInfo.expiredTime : Mute expiration time (milliseconds)
// muteInfo.roles : List of currently muted roles
});
});