// disable a channel with full update
await channel.update({disabled: true});
// disable a channel with partial update
await channel.updatePartial({set: {disabled: true}});
// enable a channel with full update
await channel.update({disabled: false});
// enable a channel with partial update
await channel.updatePartial({set: {disabled: false}});
Disabling Channels
Disable a channel
Disable a channel prevents users from viewing or creating messages on that channel. Any client-side read or write operations will results in a 403 Not Allowed
error. You can’t fetch the channel client-side, but you can query channels and receive them, you will have to use disabled:false
on your filters in order to filter the disabled channels out. The channel remains usable server-side and data can still be exported.
Channels can be re-enabled which restores historical messages and allows creation of new messages again.
// disable a channel with full update
$channel->update(["disabled" => true]);
// disable a channel with partial update
$channel->updatePartial(["disabled" => true]);
// enable a channel with full update
$channel->update(["disabled" => false]);
// enable a channel with partial update
$channel->updatePartial(["disabled" => false]);
# disable a channel with full update
channel.update({"disabled": True})
# disable a channel with partial update
channel.update_partial(to_set={"disabled": True})
# enable a channel with full update
channel.update({"disabled": False})
# enable a channel with partial update
channel.update_partial(to_set={"disabled": False})
# disable a channel with full update
channel.update({"disabled" => true})
# disable a channel with partial update
channel.update_partial({"disabled" => true})
# enable a channel with full update
channel.update({"disabled" => false})
# enable a channel with partial update
channel.update_partial({"disabled" => false})
// disable a channel with full update
Channel.update("<channel-type>", "<channel-id>")
.data(ChannelRequestObject.builder().additionalField("disabled", true).build())
.request();
// disable a channel with partial update
Channel.partialUpdate("<channel-type>", "<channel-id>")
.setValue("disabled", true)
.request();
// enable a channel with full update
Channel.update("<channel-type>", "<channel-id>")
.data(ChannelRequestObject.builder().additionalField("disabled", false).build())
.request();
// enable a channel with partial update
Channel.partialUpdate("<channel-type>", "<channel-id>")
.setValue("disabled", true)
.request();
// disable a channel with full update
var updateReq = new ChannelUpdateRequest { Data = new ChannelRequest() };
updateReq.Data.SetData("disabled", true);
await channelClient.UpdateAsync("<channel-type>", "<channel-id>", updateReq);
// disable a channel with partial update
var channelUpdates = new PartialUpdateChannelRequest
{
Set = new Dictionary<string, object> { { "disabled", true } },
};
await channelClient.PartialUpdateAsync("<channel-type>", "<channel-id>", channelUpdates);
// enable a channel with full update
var updateReq = new ChannelUpdateRequest { Data = new ChannelRequest() };
updateReq.Data.SetData("disabled", false);
await channelClient.UpdateAsync("<channel-type>", "<channel-id>", updateReq);
// enable a channel with partial update
var channelUpdates = new PartialUpdateChannelRequest
{
Set = new Dictionary<string, object> { { "disabled", true } },
};
await channelClient.PartialUpdateAsync("<channel-type>", "<channel-id>", channelUpdates);
// disable a channel with full update
channel.Update(ctx, map[string]interface{}{"disabled": true}, nil)
// disable a channel with partial update
channel.PartialUpdate(ctx, PartialUpdate{
Set: map[string]interface{}{
"disabled": true,
},
})
// enable a channel with full update
channel.Update(ctx, map[string]interface{}{"disabled": false}, nil)
// enable a channel with partial update
channel.PartialUpdate(ctx, PartialUpdate{
Set: map[string]interface{}{
"disabled": true,
},
})
// For security reasons, disabling channels is only possible via a server-side SDK
To prevent new messages from being created, while still being able to read previous messages, freeze the channel instead.
Freeze a channel
Freezing a channel will disallow sending new messages and sending / deleting reactions. Sending a message to a frozen channel will return a message of type error
. Sending and deleting reactions to frozen channels will result in a 403 Not Allowed
error. User roles with the UseFrozenChannel
permission are still able to use frozen channels as if they weren’t frozen. By default no user role has the UseFrozenChannel
permission.
val channelClient = client.channel("messaging", "general")
channelClient.updatePartial(set = mapOf("frozen" to true)).enqueue { result ->
if (result.isSuccess) {
val channel = result.data()
} else {
// Handle result.error()
}
}
const update = await channel.update(
{ frozen: true },
{ text: 'Thierry has frozen the channel', user_id: "Thierry" }
)
const update = await channel.updatePartial(
{set: {frozen: true}
)
let channelController = client.channelController(for: .init(type: .messaging, id: "general"))
channelController.freezeChannel()
$channel->update(["frozen" => true]);
channel.update({"frozen": True})
channel.update({"frozen" => true})
// Android SDK
ChannelClient channelClient = client.channel("messaging", "general");
Map<String, Object> set = new HashMap<>();
set.put("freeze", true);
List<String> unset = new ArrayList<>();
channelClient.updatePartial(set, unset).enqueue(result -> {
if (result.isSuccess()) {
Channel channel = result.data();
} else {
// Handle result.error()
}
});
// Backend SDK
ChannelRequestObject channelRequestObject = ChannelRequestObject.buildFrom(channel);
channelRequestObject.setFrozen(true);
Channel.update(channel.getType(), channel.getId())
.data(channelRequestObject)
.message(
MessageRequestObject.builder()
.text("Thierry has frozen the channel")
.userId("Thierry")
.build())
.request();
var updateReq = new ChannelUpdateRequest { Data = new ChannelRequest { Frozen = true} };
await channelClient.UpdateAsync("<channel-type>", "<channel-id>", updateReq);
channel.Update(ctx, map[string]interface{}{"frozen": true}, nil)
await channel.FreezeAsync();
Unfreeze a Channel
val channelClient = client.channel("messaging", "general")
channelClient.updatePartial(unset = listOf("frozen")).enqueue { result ->
if (result.isSuccess) {
val channel = result.data()
} else {
// Handle result.error()
}
}
const update = await channel.update(
{ frozen: false },
{ text: 'Thierry has unfrozen the channel', user_id: "Thierry" }
)
let channelController = client.channelController(for: .init(type: .messaging, id: "general"))
channelController.unfreezeChannel()
$channel->update(["frozen" => false]);
channel.update({"frozen": False})
channel.update({"frozen" => false})
// Android SDK
ChannelClient channelClient = client.channel("messaging", "general");
Map<String, Object> set = new HashMap<>();
List<String> unset = new ArrayList<>();
unset.add("freeze");
channelClient.updatePartial(set, unset).enqueue(result -> {
if (result.isSuccess()) {
Channel channel = result.data();
} else {
// Handle result.error()
}
});
// Backend SDK
ChannelRequestObject channelRequestObject = ChannelRequestObject.buildFrom(channel);
channelRequestObject.setFrozen(false);
Channel.update(channel.getType(), channel.getId())
.data(channelRequestObject)
.message(
MessageRequestObject.builder()
.text("Thierry has unfrozen the channel")
.userId("Thierry")
.build())
.request();
var updateReq = new ChannelUpdateRequest { Data = new ChannelRequest { Frozen = false} };
await channelClient.UpdateAsync("<channel-type>", "<channel-id>", updateReq);
channel.Update(ctx, map[string]interface{}{"frozen": false}, nil)
await channel.UnfreezeAsync();
Granting the Frozen Channel Permissions
Since by default no role has the UseFrozenChannel
permission, you can edit the channel type to grant the permission to a role (this is only allowed via server side API calls). Read more about user permissions here
const { grants } = await client.getChannelType("messaging");
grants.admin.push("use-frozen-channel");
await client.updateChannelType("messaging", { grants: { admin: grants.admin } });
$response = $client->getChannelType("messaging");
$response["grants"]["admin"][] = "use-frozen-channel";
$client->updateChannelType("messaging", [ "grants" => ["admin" => $response["grants"]["admin"] ] ]);
resp = client.get_channel_type("messaging")
adminGrants = resp["grants"]["admin"] + ["use-frozen-channel"]
client.update_channel_type("messaging", grants={"admin": adminGrants})
resp = client.get_channel_type("messaging")
adminGrants = resp["grants"]["admin"] + ["use-frozen-channel"]
client.update_channel_type("messaging", grants: {"admin": adminGrants})
resp, err := c.GetChannelType(ctx, "messaging")
adminGrants = append(resp.Grants["admin"], "use-frozen-channel")
c.UpdateChannelType(ctx, "messaging", map[string]interface{}{"grants": map[string][]string{"admin": adminGrants}})
// Backend SDK
ChannelTypeGetResponse resp = ChannelType.get("messaging").request();
Map<String, List<String>> currentGrants = resp.getGrants();
List<String> adminGrants = currentGrants.get("admin");
adminGrants.add("use-frozen-channel");
currentGrants.put("admin", adminGrants);
ChannelType.update("messaging")
.grants(currentGrants)
.request();
// For security reasons, granting channel permissions is only possible via a server-side SDK