# Repeated /chat/new-channel notifications

**URL:** https://meta.discourse.org/t/repeated-chat-new-channel-notifications/266071
**Category:** Bug
**Tags:** chat
**Created:** [May 24, 2023, 2:15pm UTC](https://meta.discourse.org/t/repeated-chat-new-channel-notifications/266071 "2023-05-24T14:15:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [May 24, 2023, 2:15pm UTC](https://meta.discourse.org/t/repeated-chat-new-channel-notifications/266071/1 "2023-05-24T14:15:29Z")

</div>

While playing around with the message bus, I saw that every time I receive a chat message, I get a `/chat/new-channel` notification with it. This happens even when both users have the chat open.

```plaintext
[{"global_id":61583779,"message_id":134,"channel":"/chat/4","data":{"chat_message":{"id":6,"message":"nice to see you too","cooked":"<p>nice to see you too</p>","created_at":"2023-05-24T14:07:02.800Z","excerpt":"nice to see you too","available_flags":[],"thread_title":null,"chat_channel_id":4,"user":{"id":152,"username":"testuser","name":"testuser","avatar_template":"https://avatars.discourse-cdn.com/v4/letter/t/e495f1/{size}.png","moderator":false,"admin":false,"staff":false,"new_user":false,"primary_group_name":null,"assign_icon":"user-plus","assign_path":"/u/testuser/activity/assigned"},"chat_webhook_event":null,"uploads":[]},"type":"sent","staged_id":"66122c8d-ad8e-4754-b04a-e0ff75c4e898","staged_thread_id":null}}]
|
[{"global_id":61583780,"message_id":69,"channel":"/chat/4/new-messages","data":{"channel_id":4,"message_id":6,"user_id":152,"username":"testuser","thread_id":null}}]
|
[{"global_id":61583781,"message_id":20767,"channel":"/chat/new-channel","data":{"channel":{"id":4,"allow_channel_wide_mentions":true,"chatable":{"id":1,"users":[{"id":152,"username":"testuser","name":"testuser","avatar_template":"https://avatars.discourse-cdn.com/v4/letter/t/e495f1/{size}.png","custom_fields":{},"assign_icon":"user-plus","assign_path":"/u/testuser/activity/assigned"}]},"chatable_id":1,"chatable_type":"DirectMessage","chatable_url":null,"title":"@testuser","slug":null,"last_message_sent_at":"2023-05-24 14:07:02 UTC","status":"open","memberships_count":0,"current_user_membership":{"following":true,"muted":false,"desktop_notification_level":"always","mobile_notification_level":"always","chat_channel_id":4,"last_read_message_id":5},"meta":{"message_bus_last_ids":{"channel_message_bus_last_id":134,"new_messages":69,"new_mentions":0},"can_join_chat_channel":true},"threading_enabled":false}}}]
|

```

and then when another message is sent

```plaintext
[{"global_id":61583803,"message_id":135,"channel":"/chat/4","data":{"chat_message":{"id":7,"message":"and another message","cooked":"<p>and another message</p>","created_at":"2023-05-24T14:08:01.128Z","excerpt":"and another message","available_flags":[],"thread_title":null,"chat_channel_id":4,"user":{"id":152,"username":"testuser","name":"testuser","avatar_template":"https://avatars.discourse-cdn.com/v4/letter/t/e495f1/{size}.png","moderator":false,"admin":false,"staff":false,"new_user":false,"primary_group_name":null,"assign_icon":"user-plus","assign_path":"/u/testuser/activity/assigned"},"chat_webhook_event":null,"uploads":[]},"type":"sent","staged_id":"67a062f9-28de-42c8-a037-c3d272584c3d","staged_thread_id":null}}]
|
[{"global_id":61583804,"message_id":70,"channel":"/chat/4/new-messages","data":{"channel_id":4,"message_id":7,"user_id":152,"username":"testuser","thread_id":null}}]
|
[{"global_id":61583805,"message_id":20768,"channel":"/chat/new-channel","data":{"channel":{"id":4,"allow_channel_wide_mentions":true,"chatable":{"id":1,"users":[{"id":152,"username":"testuser","name":"testuser","avatar_template":"https://avatars.discourse-cdn.com/v4/letter/t/e495f1/{size}.png","custom_fields":{},"assign_icon":"user-plus","assign_path":"/u/testuser/activity/assigned"}]},"chatable_id":1,"chatable_type":"DirectMessage","chatable_url":null,"title":"@testuser","slug":null,"last_message_sent_at":"2023-05-24 14:08:01 UTC","status":"open","memberships_count":0,"current_user_membership":{"following":true,"muted":false,"desktop_notification_level":"always","mobile_notification_level":"always","chat_channel_id":4,"last_read_message_id":6},"meta":{"message_bus_last_ids":{"channel_message_bus_last_id":135,"new_messages":70,"new_mentions":0},"can_join_chat_channel":true},"threading_enabled":false}}}]
|

```

The [source](https://github.com/discourse/discourse/blob/main/plugins/chat/app/controllers/chat/chat_controller.rb#L125-L135) seems to imply that a new-channel event is sent every time when a message is created.

And of course, if this is a complete misunderstanding on my side on how things should work, feel free to laugh at me while you move this to #Support 😉

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [May 25, 2023, 6:09pm UTC](https://meta.discourse.org/t/repeated-chat-new-channel-notifications/266071/2 "2023-05-25T18:09:16Z")

</div>

I will investigate this tomorrow thanks. We have been movings lots of things around subscriptions lately, it’s possible we have regressed on this.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [May 25, 2023, 8:02pm UTC](https://meta.discourse.org/t/repeated-chat-new-channel-notifications/266071/4 "2023-05-25T20:02:47Z")

</div>

So I had a quick look already, I don’t think it’s a regression, however, this is now something we could probably get rid off as we have automatic logic to get the channel if not present (simply put: if not in your sidebar).

It would have been harder few months ago.

Will double check and try to finish this tomorrow, good call thanks 👍 This was on a list of things I have to check to allow stricter number of channels in the sidebar, so that’s one less thing 🚀

[https://github.com/discourse/discourse/pull/21755](https://github.com/discourse/discourse/pull/21755)

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [May 26, 2023, 3:13pm UTC](https://meta.discourse.org/t/repeated-chat-new-channel-notifications/266071/5 "2023-05-26T15:13:59Z")

</div>

Ok I just merged this, it should now only send the new channel event when the channel is not in your sidebar.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [May 27, 2023, 3:26pm UTC](https://meta.discourse.org/t/repeated-chat-new-channel-notifications/266071/6 "2023-05-27T15:26:59Z")

</div>


