Channel Message Count

Message counting

Stream Chat can keep track of the number of messages in a channel. This is useful for displaying message counts in your UI.

Message counting is disabled by default and can be enabled on a channel type level by setting the count_messages option to true when creating or updating a channel type.

Message counting only works on newly created channels. Existing channels will not have their message count updated when this feature is enabled.

Enabling message counting

// Create a new channel type with message counting enabled
await client.createChannelType({
  name: "public",
  count_messages: true,
});

Retrieving message count

When message counting is enabled for a channel type, the message count can be retrieved from the channel object.

When you query or watch a channel, the message count will be available in the message_count field of the channel object.

When the `count_messages` setting is enabled for a channel and messages are added or deleted, every event generated as a result of those operations (e.g: `message.new` or `message.deleted`) will include the updated count in the `channel_message_count` field.
int32 MessageCount = Channel->GetMessageCount();
© Getstream.io, Inc. All Rights Reserved.