# Message count in group channel with javascript sdk

**URL:** <https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684>\
**Category:** JavaScript\
**Created:** [February 8, 2021, 5:54pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684 "2021-02-08T17:54:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafa](https://community.sendbird.com/u/Rafa)\
**Post date:** [February 8, 2021, 5:54pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/1 "2021-02-08T17:54:08Z")

</div>

How can I get the message count of a group channel with the javascript sdk?

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [February 8, 2021, 6:12pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/2 "2021-02-08T18:12:59Z")

</div>

Rafa,

First off, welcome to the Sendbird community! We’re glad you’re here. Just to clarify, are you looking for total message count, unread message count or something else?

Thanks!

---

<div class="post-metadata">

**Author:** ![Rafa](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafa](https://community.sendbird.com/u/Rafa)\
**Post date:** [February 8, 2021, 6:14pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/3 "2021-02-08T18:14:35Z")

</div>

> [@Tyler](#):
>
> Rafa,
> 
> First off, welcome to the Sendbird community! We’re glad you’re here. Just to clarify, are you looking for total message count, unread message count or something else?
> 
> Thanks!

Hey Tyler, thank you 🙂

Looking for the total message count

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [February 8, 2021, 6:21pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/4 "2021-02-08T18:21:17Z")

</div>

To get the total message count, you could grab the channel, generate a list of messages and grab the count of that list.

That could look something like this:

```javascript
sb.GroupChannel.getChannel(channelURL, (groupChannel, error) => {
  const listQuery = groupChannel.createPreviousMessageListQuery();
  listQuery.load((messages, error) => {
      const totalMessageCount = messages.length
    });

    dispatch({
      type: GET_MESSAGES,
      payload: messages,
    });
  });

```

---

<div class="post-metadata">

**Author:** ![Rafa](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafa](https://community.sendbird.com/u/Rafa)\
**Post date:** [February 8, 2021, 6:31pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/5 "2021-02-08T18:31:23Z")

</div>

Doesn’t the list query have a limit max of 100?  
Fetching every single message in the channel would also be expensive. Is there no way to only ask for the count?

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [February 8, 2021, 6:58pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/6 "2021-02-08T18:58:04Z")

</div>

You are correct that the SDK has a limit of 100. The Platform API does have a bit of a larger limit, but it would still be limited. This isn’t a data point that we track currently, and thus any solution would ultimately be clunky and expensive.

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [February 8, 2021, 8:40pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/7 "2021-02-08T20:40:40Z")

</div>

@Rafa,

One of my colleague pointed out that while the Javascript SDK does not provide this information, the Platform API does: [https://sendbird.com/docs/chat/v3/platform-api/guides/messages#2-view-total-number-of-messages-in-a-channel](https://sendbird.com/docs/chat/v3/platform-api/guides/messages#2-view-total-number-of-messages-in-a-channel)

Is there a specific purpose for needing the message count of each channel?

---

<div class="post-metadata">

**Author:** ![Rafa](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafa](https://community.sendbird.com/u/Rafa)\
**Post date:** [February 8, 2021, 10:49pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/8 "2021-02-08T22:49:26Z")

</div>

Yeah, I would like to cache my messages to redux and use the total channel message count to tell me if the cache has gotten out of sync with your servers.

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [February 8, 2021, 11:12pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/9 "2021-02-08T23:12:41Z")

</div>

Rafa,

It sounds like [messageChangeLogs](https://sendbird.github.io/core-sdk-javascript/module-model_baseChannel-BaseChannel.html#getMessageChangeLogsByTimestamp) would be better suited for what you’re looking to accomplish. Have you taken a look at that yet?

---

<div class="post-metadata">

**Author:** ![Slava\_Alexeev](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/slava_alexeev/32/3542_2.png) [@Slava\_Alexeev](https://community.sendbird.com/u/Slava_Alexeev)\
**Post date:** [March 15, 2023, 4:47pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/10 "2023-03-15T16:47:43Z")

</div>

Hey @Tyler,  
Now we need to have total count of messages per channel because our UI supposed to display it. Is there any way to get it now?

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [March 20, 2023, 11:45pm UTC](https://community.sendbird.com/t/message-count-in-group-channel-with-javascript-sdk/1684/11 "2023-03-20T23:45:54Z")

</div>

@Slava_Alexeev,

There is currently no way to retrieve the total list of messages per channel.
