Freezing Channels

Freezing a channel prevents users from sending new messages and adding or deleting reactions.

Sending a message to a frozen channel returns an error message. Attempting to add or delete reactions returns a 403 Not Allowed error.

User roles with the UseFrozenChannel permission can still use frozen channels normally. By default, no user role has this permission.

Freeze a Channel

// 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
chat.updateChannelPartial(channel.getType(), channel.getId(),
    UpdateChannelPartialRequest.builder()
        .set(Map.of("frozen", true))
        .build()).execute();

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
chat.updateChannelPartial(channel.getType(), channel.getId(),
    UpdateChannelPartialRequest.builder()
        .set(Map.of("frozen", false))
        .build()).execute();

Granting the Frozen Channel Permission

Permissions are typically managed in the Stream Dashboard under your app's Roles & Permissions settings. This is the recommended approach for most use cases.

To grant permissions programmatically, update the channel type using a server-side API call. See user permissions for more details.

// Backend SDK
var resp = chat.getChannelType("messaging").execute().getData();
var currentGrants = resp.getGrants();

List<String> adminGrants = new ArrayList<>(currentGrants.get("admin"));
adminGrants.add("use-frozen-channel");
currentGrants.put("admin", adminGrants);

chat.updateChannelType("messaging", UpdateChannelTypeRequest.builder()
    .grants(currentGrants)
    .automod(resp.getAutomod())
    .automodBehavior(resp.getAutomodBehavior())
    .maxMessageLength(resp.getMaxMessageLength())
    .build()).execute();