It is possible to do it through the rails console (and also the API too), but I would consider carefully whether you should or not. If a user has deliberately made a choice to Watch or Mute a category (or tag or topic) then overriding that choice is likely going to be undesired. They can also simply flick it back to what it was, so you may not gain anything.
The idea is to roll back the new default setting (watching a certain category) and then let people change it as they wish.
I noticed now that the above command User.all.each do |user| CategoryUser.batch_set(user, :watching, [<id>]) end somehow did not work to change the preferences for all users. Any idea why ? Even better would be to append the new tracking preference to the existing user tracking preferences…
P.S. we’re a tiny community and I know that only an even smaller fraction took the time to adjust their preferences (;
For anyone who hasn’t specifically set a category at a notification level, resetting the default category watching and applying it historically should reset those to normal levels.
If the numbers are small, using the UI or API may be a safer bet than the rails console. How many people are we talking about?
For understanding, the category in question is named Announcements and its ID is 22.
I did exactly this before also trying the command. But still after both, at a new post in Announcements, only some users get sent an email.
What could have happened is that users unsubscribed from the email notifications because the digest email only contained “minor” activity (i.e. no posts from Announcements as described in the related issue linked to previously)
Do you have the data explorer installed? If so, have you got a query to see how many of your users don’t have the right tracking and/or email preference?
I think we need to know a little more detail before working out a solution. The category_users table only keeps a record of active category notification levels, so if someone doesn’t have one then the data won’t be in the table to change via the rails console. (for instance, if I add #site-feedback to the default categories watching admin setting it will add a record in category_users for each user, and when I reset the setting it will delete those records again).
I can confirm that User.all.each do |user| CategoryUser.batch_set(user, :watching, [22]) changed the tracking preferences of all users to watch the desired category (22 | Announcements); as this query lists all the users:
SELECT *
FROM category_users
WHERE category_id = '22' AND notification_level = '3'
And this query lists only 1 user:
SELECT *
FROM user_options uo
WHERE uo.email_level = '2'
The question is now, why so many users don’t get an email sent when there’s a new post in category 22 “Announcements”
P.S. I tinker around for the SQL queries and don’t know how to join them.
Hi. I did not find a solution yet. I can’t get my head around of the necessary user preferences to receive post notification emails for watched topics. Any idea ? Thx !
Just in case, I’m still inquiring and trying to solve this issue. I isolated the settings of one of our users which has the default settings of watching a certain category (‘Announcements’) but who does not receive e-mail notifications for new posts:
user
mailing_list_mode
email_digests
external_links_in_new_tab
enable_quoting
dynamic_favicon
automatically_unpin_topics
digest_after_minutes
auto_track_topics_after_msecs
new_topic_duration_minutes
last_redirected_to_top_at
email_previous_replies
email_in_reply_to
like_notification_frequency
mailing_list_mode_frequency
include_tl0_in_digests
notification_level_when_replying
theme_key_seq
allow_private_messages
homepage
theme_ids
hide_profile_and_presence
text_size_key
text_size_seq
email_level
email_messages_level
title_count_mode_key
enable_defer
timezone
enable_allowed_pm_users
dark_scheme
skip_new_user_tips
color_scheme
default_calendar
oldest_search_log_date
chat_enabled
only_chat_push_notifications
chat_sound
dismissed_channel_retention_reminder
dismissed_dm_retention_reminder
bookmark_auto_delete_preference
ignore_channel_wide_mention
chat_email_frequency
enable_experimental_sidebar
seen_popups
chat_header_indicator_preference
sidebar_link_to_filtered_list
sidebar_show_count_of_new_items
watched_precedence_over_muted
chat_separate_sidebar_mode
topics_unread_when_closed
show_thread_title_prompts
JohnDoe
false
true
true
true
false
true
10080
240000
2880
2023-06-13T08:25:13.000Z
1
false
1
1
true
2
0
true
NULL
{}
false
0
0
1
1
0
false
Europe/Somwhere
false
NULL
false
NULL
0
NULL
true
NULL
NULL
NULL
NULL
3
NULL
1
false
{1,2,3,4,5}
0
false
false
NULL
0
true
true
I really can’t see why this issue arises because this is the user’s line when I query the users watching category ‘Announcements’:
id
category
user
notification_level
last_seen_at
123
Announcements
JohnDoe
3
NULL
Are there any other settings I am missing ? Could it be that the user clicked unsubscribe in one of the notification emails and that changed their email settings ?
If a user selected either the “stop watching all topics in the <category_name> category” or the “Don’t send me any mail from Discourse” options, you will see the changes on their preferences page. Either the category will have been removed from their watched category list, or their email preferences will be changed so that all settings on their email page will be set to “never”.
It’s more difficult to see the change if the user selected the “stop watching this topic” option. In that case, you could impersonate the user from their admin page, then visit the topic to see if their notification level for the topic has changed from “watching” to “tracking”. You can also get the information about their notification level for the topic from the Rails console:
Before getting too caught up in this, go to the site’s Skipped Email Logs page. You can navigate to it from the admin sidebar. Enter the user’s email into the “To Address” field that’s at the top of the page. It might show you details about why the particular email was not sent to the user.