# "X new / updated topics" gets triggered for muted topics

**URL:** https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226
**Category:** Bug
**Tags:** planned
**Created:** [Décembre 2, 2015, 2:51 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226 "2015-12-02T02:51:19Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Drew\_Warwick](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/drew_warwick/32/80591_2.png) [@Drew\_Warwick](https://meta.discourse.org/u/Drew_Warwick)
#### Post date: [Décembre 2, 2015, 2:51 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/1 "2015-12-02T02:51:20Z")

</div>

I had been getting the “X new / updated topics” notification when there hadn’t actually been a new topic occasionally, but as it turns out there were new topics – they were just muted. They didn’t appear in Latest because they were muted, but they still set off the notification. This probably shouldn’t happen.

---

<div class="post-metadata">

### Author: ![Drew\_Warwick](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/drew_warwick/32/80591_2.png) [@Drew\_Warwick](https://meta.discourse.org/u/Drew_Warwick)
#### Post date: [Décembre 2, 2015, 7:30 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/2 "2015-12-02T19:30:51Z")

</div>

I just found it it also happens for unlisted threads too – not just muted ones.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [Décembre 2, 2015, 7:36 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/3 "2015-12-02T19:36:49Z")

</div>

Is this happening only while you are logged in or are you also getting Notifications for posts that were created while you were logged out?

---

<div class="post-metadata">

### Author: ![Drew\_Warwick](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/drew_warwick/32/80591_2.png) [@Drew\_Warwick](https://meta.discourse.org/u/Drew_Warwick)
#### Post date: [Décembre 2, 2015, 7:55 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/4 "2015-12-02T19:55:59Z")

</div>

It’s only happened while I’ve been logged in so far, but that’s mostly because I’m never logged out – I always have a window for the forum up on my secondary monitor.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [Mai 22, 2017, 10:23 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/5 "2017-05-22T22:23:24Z")

</div>

Is there a way to improve on this for 1.8 that is not risky @eviltrout?

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [Mai 23, 2017, 2:23 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/6 "2017-05-23T14:23:37Z")

</div>

I’ll take a look and see

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Mai 23, 2017, 3:00 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/8 "2017-05-23T15:00:01Z")

</div>

This is nasty hard, cause the message bus message we ship goes to “everyone” it does not filter out users that have the topic muted.

To fix this we would need

- Either have the client be aware of topic ids for muted topics, which could be tens of thousands of ids (so this is a non starter)

- Or, Have the client issue an extra AJAX call to double check if any of the topics in the batch of refreshed topics is muted. Which also is nasty.

I do not think anything easy can be done here.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [Mai 23, 2017, 3:02 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/9 "2017-05-23T15:02:42Z")

</div>

What about the server doing the filtering?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Mai 23, 2017, 3:19 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/10 "2017-05-23T15:19:02Z")

</div>

How can it do that?

- Post is created

- We trigger a message bus message to all groups with access to the topic informing that a new post is created

We would have hint that message to filter out all users that have the topic muted, that sort that out.

So, now what we have is:

```plaintext
 def self.publish_latest(topic, staff_only=false)
    return unless topic.archetype == "regular"

    message = {
      topic_id: topic.id,
      message_type: "latest",
      payload: {
        bumped_at: topic.bumped_at,
        topic_id: topic.id,
        category_id: topic.category_id,
        archetype: topic.archetype
      }
    }

    group_ids =
      if staff_only
        [Group::AUTO_GROUPS[:staff]]
      else
        topic.category && topic.category.secure_group_ids
      end
    MessageBus.publish("/latest", message.as_json, group_ids: group_ids)
  end

```

What we kind of want is:

```ruby
MessageBus.publish("/latest", message.as_json, group_ids: group_ids, server_filter: lambda do |user_id|
   return topic.not_muted?(user_id)
end
)

```

It has caveats cause it means that when people ask for the message we would have to issue a query, nothing in message bus works this way at the moment.

The trivial implementation does not work, cause the user\_id list can be gigantic

```ruby
MessageBus.publish("/latest", message.as_json, group_ids: group_ids, exclude_user_ids: user_ids_muting_topic)

```

This one _may_ sort of work,

```ruby
MessageBus.publish("/latest", message.as_json, group_ids: group_ids, exclude_user_ids: user_ids_muting_topic_seen_in_last_24_hours)

```

It is a 🌋 of worms.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [Mai 23, 2017, 3:45 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/11 "2017-05-23T15:45:59Z")

</div>

> <https://github.com/discourse/discourse/blob/main/app/models/topic_tracking_state.rb#L93-L94>

Here we already having user-wise filtered MessageBus. Can we do something like above here?

Currently all users are subscribed to `/latest` MessageBus. Additionally all logged in users should be subscribed to `/latest/muted/:USERID` MessageBus. Then in server we should publish `latest` action on both MessageBuses like below

```ruby
TopicUser.each do # Should select only muted topic users
  MessageBus.publish("/latest/muted/#{tu.user_id}", message.as_json, group_ids: group_ids)
end
MessageBus.publish("/latest", message.as_json, group_ids: group_ids)

```

In client side if a topic is received on both MessageBuses then we shouldn’t display it on updated topics.

Ignore me if I am wrong. I don’t have deep knowledge on how MessageBuses working.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Mai 23, 2017, 3:58 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/12 "2017-05-23T15:58:17Z")

</div>

The issue I have with that is that a single post creation could create thousands of messages if thousands of people are muting a topic.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [Mai 23, 2017, 4:05 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/13 "2017-05-23T16:05:28Z")

</div>

Yes. I noticed that issue. We are having the same problem on `/unread` MessageBus. If thousands of people tracking a topic then a single post creation will send thousands of messages in `/unread` too. Somehow we have to fix both.

Is there any chance to send messages only to the people who online (like `last_seen_at > 1.hour.ago`) ?

---

<div class="post-metadata">

### Author: ![ChrisBeach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisbeach/32/214628_2.png) [@ChrisBeach](https://meta.discourse.org/u/ChrisBeach)
#### Post date: [Août 16, 2017, 8:45 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/14 "2017-08-16T08:45:25Z")

</div>

Our users are picking up on this issue too.

An uneducated suggestion - If update messages contain topic ids, could these be filtered on client-side based on a user’s mute list? Caching the mute-list client-side would probably be okay as I expect most users probably only mute a small handful of topics (and in any case, we’d use a bounded cache of, say, 1000 most-recently-muted topic ids). No changes to message bus infrastructure required - it would be downstream of that.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Août 16, 2017, 12:41 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/15 "2017-08-16T12:41:03Z")

</div>

Yeah that is doable, does increase initial payload, we could defer loading the muted list till we get the first message something that helps

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [Mai 20, 2019, 12:25 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/16 "2019-05-20T12:25:05Z")

</div>

> [@ChrisBeach](#):
>
> Our users are picking up on this issue too.

Some of our users have been raising this bug with us too lately.

It’s been around for quite some time by the looks of it, any more thoughts on a fix for this one?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [Mai 20, 2019, 6:08 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/17 "2019-05-20T18:08:57Z")

</div>

We should eventually fix this @sam, I feel a final safety check here (wait, before I show this banner to this user, are all the topics I am notifying the user about muted _by this user_?) could make sense.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Mai 21, 2019, 7:22 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/18 "2019-05-21T07:22:43Z")

</div>

If we ship to the client the list of muted categories / tags we may be able to filter these out on the client with radical and complex changes to the server.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [Mai 21, 2019, 7:27 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/19 "2019-05-21T07:27:34Z")

</div>

If it’s super hard it can wait – I was thinking more of a “saving throw” that the client does when it gets that message, _if_ the user has muted stuff.

Ironically when the user clicks on the “new replies / topics” notice .. this happens, yes? At the time the user clicks, if _no_ new topics appear then you know by definition it was all muted stuff.

It would be a lot of extra work though, you’d basically have to pre-emptively do _all the actual work of the user clicking the notice_, then compare the results, then choose not to show the banner because the topic list is unchanged.

So yes, I can see why this would be quite painful.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Mai 21, 2019, 7:30 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/20 "2019-05-21T07:30:56Z")

</div>

It think it is doable there are just a few changes that we need in place

- We need to ensure that muted tags / muted categories are included in the “current user serializer”, this adds 2 queries unconditionally to every initial page load

- We need to amend the message bus message to include tags cause now it only has categories

- We need to wire in the business logic of where to apply this filter (clearly you want the bar to show up if you are parked on a muted category vs latest)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [Mai 21, 2019, 7:31 UTC](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226/21 "2019-05-21T07:31:28Z")

</div>

> [@sam](#):
>
> We need to ensure that muted tags / muted categories

That’s not enough though because users can mute individual topics.

I think I am fine deferring on this quite a bit longer.

[Page suivante](https://meta.discourse.org/t/x-new-updated-topics-gets-triggered-for-muted-topics/36226.md?page=2)
