New category automatically as muted or watching for all users

(Manfred Bayer Lemerz) #1

When we add a new category it is automatically as normal for all user can we also set that has a different status like watching or muted?

(Jeff Atwood) #2

You can do that via the Rails console, but it’d be a manual command.

(Felix Freiberger) #3

How would that look like?

I’d assume it’s a loop over all users where for each user, something like

CategoryUser.create!(user_id:, <INSERT HERE>, CategoryUser.notification_levels[:muted])

is run – but my Ruby skills are quite lacking, and I assume this would crash if the user already had an entry here.

CategoryUser.batch_set is also looking promising…


User.all.each do |user| CategoryUser.batch_set(user, :muted, [7]) end

do the trick (for category 7)?

How do I set category tracking level defaults historically
(Felix Freiberger) #4

After some toying around, it looks like my last command did work :slight_smile:


yup. It does, however it removes all other already muted category. Is there a way to append new muted category instead?

(Sam Saffron) #6

Not following, can you give me a concrete example of what you are trying to do.

(Chris Beach) #7

Along similar lines, I’m using groups to allow members to opt in to see special-interest categories.

Ideally, upon opting in to such a category, members would be “watching first post” on that category. I’m not sure if/how I can configure this.


Sorry for late answer.

Here’s my usecase.
I would like every new category to be set to “mute” for every user, so that they need to unmute it if they want to get notifications (specially when using mailinglist mode).
In admin settings under “User preferences” I added all the categories I want to have “muted” by default. Whenever there is newly created category I can add it to that list. This however covers only the new users that just created an account. I’m looking for a way to easily mark each new category for each existing user as “muted” by default.
I used rail console query from above:
User.all.each do |user| CategoryUser.batch_set(user, :muted, [7]) end
but that instead of setting new category to “mute” only, overwrittes all muted categories users setup previously, leaving only this new category as muted.

I’m looking for query that would only add new category to the already setup list by users and not overwrite.

Does this make more sense? Sorry if I make it sound unlcear.