Make members of a group watch a category by default

(Alex Armstrong) #52

AFAICT, it works fine. It’s mostly just a cleaner way to do the same ol’ stuff.

But, as @watchmanmonitor pointed out on GitHub, you should fork the repository in order to customize it. This will prevent conflicts since the customization happens right in the code.

BTW, @Jared_Needell had an interesting bit about user.staged that I discarded, as I wasn’t sure what it was doing. My guess is that it ignored staged users?

I also agree with all of @watchmanmonitor’s input, but I’ll reply in @fefrei’s thread.

(Alex Armstrong) #53

I’m wondering if any of the mailing list crowd have played around with the updated group PMs.

I’m thinking of using a category for inter-group communication and using the group PM to allow non-group users to contact them. (I thought of doing it the other way around, but it wouldn’t make sense in my case. Non-group users might not want their messages publicly viewable.)

I don’t know if group PMs are covered by Sam’s recent changes to the watching feature: Watching and tracking implementation for tags and categories

In any case, if they’re not now, I assume they would be eventually.

Can someone suggest how to programatically change the watch state for group PMs?

I’m looking for the group PM equivalent for this: discourse-watch-category/plugin.rb at master · amical/discourse-watch-category · GitHub

(Alex Armstrong) #54

@techAPJ: Can you point me to some example of how to script users watching group PMs and tags?

(Robert) #57

@alehandrof, for the record:

# based on
groups = {
  "Group_1" => {},
  "Group_2" => {category: "News"},
  "Group_3" => {tag: "content"},
  "Group_4" => {tag: "content", category: "News"}

# levels: :watching :watching_first_post etc.
level = :watching

groups.each do |group_name, subscriptions|
  group = Group.find_by_name(group_name)
  next if group.nil? # skip if group not found
  puts "group: #{}"
  # watch group inbox
  # found in discourse/spec/services/post_alerter_spec.rb
  # GroupUser.where(user_id:, group_id: level) # change for one user
  GroupUser.where(group_id: GroupUser.notification_levels[level]) # change for whole group
  # watch tag
  tag_name = subscriptions[:tag]
  if tag_name
    tag = Tag.find_by_name(tag_name)
    unless tag.nil?
      puts "tag: #{}"
      # TagUser.where(tag_id: GroupUser.notification_levels[:level])
      group.users.each do |user|
        watched_tags = TagUser.lookup(user, level).pluck(:tag_id)
        TagUser.change(,, TagUser.notification_levels[level]) unless watched_tags.include?(
  # watch category
  category_slug = subscriptions[:category]
  if category_slug
    category = Category.find_by_slug(category_slug)
    unless category.nil?
      puts "category: #{}"
      group.users.each do |user|
        watched_categories = CategoryUser.lookup(user, level).pluck(:category_id)
        CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[level], unless watched_categories.include?(

Watching group PMs by default
(Christoph) #58

What will happen if I uninstall/deactivate this plugin? Will all watch settings stay as they are or will all group-members be “unsubscribed” from their category?

(Alex Armstrong) #59

The settings will stay the same if you disable/uninstall the plugin.

This post explains how to change settings for multiple users if, for example, you want to have them stop watching a category (i.e., “unsubscribe”):

(Alex Armstrong) #60

@rriemann Your code looks interesting, but I haven’t had a chance to play around with it. Sorry for taking so long to respond. Your code, if it does what it seems to, is much better than mine. I will happily fold it into my plugin, if you (or someone else) doesn’t want to take over this rickety plugin :slight_smile:

(Robert) #61

I cannot work on this at the moment. Plugin? I think there should be some setting in vanilla Discourse.

(Alex Armstrong) #62

Agreed :slight_smile: But in the meantime, I’d like to have a UI to configure this behavior, and I’m tight on time (and with limited skills). I won’t be able to dig in to see how plugin config UIs work until end of May probably, but I might have time then.

(Christoph) #63

Is your plugin still working as intended? I forked it yesterday and adopted it but after 12 hours the people it the respective groups are still not watching the respective categories…

I changed :watching to :watching_first_post, maybe there is a problem with that?

No errors logged.

Update: Stupid me: I used the category names instead if the slugs. It should work now, I guess (any way of knowing at what times the script is executed?) Edit: yes there is: check the WatchCategory job at http://<your-site>/sidekiq/scheduler

(Tobias Eigen) #64

You can always go to siteurl/sidekiq/scheduler and run it yourself.

(Alex Armstrong) #65

Hi Christoph. Sorry for not answering earlier. Good to know you figured it out. Admittedly, it’s not a very intuitive plugin. An admin UI would go along way towards making it more usable.

(Erlend Sogge Heggen) #66

This can probably be closed now, although…

One feature I’m missing is the ability to change these settings via a category’s own settings. I went looking for this setting when a customer requested it, and the first place I looked was the settings screen of a specific category.


(Alex Armstrong) #67

Has this been added as core functionality?

(Erlend Sogge Heggen) #68

If you’re referring to the ‘default categories watching’ setting and it’s cousins, then yes, it’s in core.

(Alex Armstrong) #69

I’m not sure what the cousins you’re referring to are, but the default categories watching setting doesn’t accomplish the OP’s goal:

I don’t just mean there’s no UI like that. AFAIK, the only way to get a specific group (not all users) to “watch” (or “watch first post” or whatever) a specific category – and to have that happen after the user has been created – is by using a plugin, such as the one I use.

I’d be happy to ditch this workaround, but I don’t see this functionality in core. Or have I missed something in a recent update?

Wording for private/secure categories
(David Baker) #70

I don’t see in this thread whether staff have answered the question if they agree this feature should be in core. Knowing if it’s in the pipeline or not would help.

(Leo McArdle) #71

I created an RFC for the implementation side of this a while back (I’m sure I linked to it somewhere in this thread):

But it looks like the consensus is for implementing this as a plugin. That’s something I plan to do at some point, but I can’t say when.

(Mathieu Boespflug) #72

But it looks like the consensus is for implementing this as a plugin. That’s something I plan to do at some point, but I can’t say when.

@LeoMcA is this something you got around to doing in the end?

(Leo McArdle) #73

Not yet, I’ll post in that other thread when I do :slight_smile: