# onChannelChanged returns wrong unreadMessageCount

**URL:** <https://community.sendbird.com/t/onchannelchanged-returns-wrong-unreadmessagecount/4439>\
**Category:** JavaScript\
**Tags:** group-channel, chatsdk\
**Created:** [April 14, 2022, 7:00am UTC](https://community.sendbird.com/t/onchannelchanged-returns-wrong-unreadmessagecount/4439 "2022-04-14T07:00:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [April 14, 2022, 7:00am UTC](https://community.sendbird.com/t/onchannelchanged-returns-wrong-unreadmessagecount/4439/1 "2022-04-14T07:00:43Z")

</div>

Hi, I was using the `onChannelChanged` event to get the latest `unreadMessageCount` from the `channel` object and display it on our UI. I noticed if I delete the **last read** message, the `unreadMessageCount` will be decremented by 1, which shouldn’t happen.

Here’s an example, let’s say we have a total of 5 messages and 2 of them are unread:

- message\_1 (read)
- message\_2 (read)
- message\_3 (read) - last read
- message\_4 (unread)
- message\_5 (unread)

When I delete either **message\_1** OR **message\_2** , the `unreadMessageCount` remains as 2, which is correct.  
When I delete either **message\_4** OR **message\_5** , the `unreadMessageCount` gets decremented by 1, which is also correct since they are part of the unread messages.  
But when I delete **message\_3** (last read), the `unreadMessageCount` got incorrectly decremented by 1. Supposedly it should remain as 2, because **message\_4** and **message\_5** are still unread.

For your information:

- I performed the message deletion from the dashboard as our app doesn’t support deleting message yet
- I did not call `markAsRead` in between the message deletions

---

<div class="post-metadata">

**Author:** ![Dhaval\_Patel](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/dhaval_patel/32/1956_2.png) [@Dhaval\_Patel](https://community.sendbird.com/u/Dhaval_Patel)\
**Post date:** [April 15, 2022, 8:28pm UTC](https://community.sendbird.com/t/onchannelchanged-returns-wrong-unreadmessagecount/4439/2 "2022-04-15T20:28:12Z")

</div>

Hi @hewong,

We will run some tests on our end and let you know of our findings. Meanwhile, if you have any other questions please let us know.

Best,  
Dhaval.

---

<div class="post-metadata">

**Author:** ![Dhaval\_Patel](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/dhaval_patel/32/1956_2.png) [@Dhaval\_Patel](https://community.sendbird.com/u/Dhaval_Patel)\
**Post date:** [April 26, 2022, 9:32pm UTC](https://community.sendbird.com/t/onchannelchanged-returns-wrong-unreadmessagecount/4439/4 "2022-04-26T21:32:32Z")

</div>

Hi @hewong,

I was able to reproduce the issue and have notified our engineering team regarding this. I will keep you updated on the progress, Meanwhile, if you have any other questions please let us know.

Best,  
Dhaval.

---

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [April 27, 2022, 12:47am UTC](https://community.sendbird.com/t/onchannelchanged-returns-wrong-unreadmessagecount/4439/5 "2022-04-27T00:47:14Z")

</div>

Alright thanks for the update!
