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("<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();

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.

// 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();

Unfreeze a Channel

// 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();

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

// 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();
© Getstream.io, Inc. All Rights Reserved.