-
Notifications
You must be signed in to change notification settings - Fork 17
/
plugin.rb
53 lines (47 loc) · 1.59 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
# name: Watch Category
# about: Watches a category for all the users in a particular group
# version: 0.2
# authors: Arpit Jalan
# url: https://github.com/discourse/discourse-watch-category-mcneel
module ::WatchCategory
def self.watch_category!
mcneel_private_category = Category.find_by_slug("mcneel-private")
mcneel_group = Group.find_by_name("mcneel")
unless mcneel_private_category.nil? || mcneel_group.nil?
mcneel_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
if watched_categories.exclude?(mcneel_private_category.id)
CategoryUser.set_notification_level_for_category(
user,
CategoryUser.notification_levels[:watching],
mcneel_private_category.id,
)
end
end
end
reseller_category = Category.find_by_slug("resellers")
reseller_group = Group.find_by_name("resellers")
return if reseller_category.nil? || reseller_group.nil?
reseller_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
if watched_categories.exclude?(reseller_category.id)
CategoryUser.set_notification_level_for_category(
user,
CategoryUser.notification_levels[:watching],
reseller_category.id,
)
end
end
end
end
after_initialize do
module ::WatchCategory
class WatchCategoryJob < ::Jobs::Scheduled
every 1.day
def execute(args)
WatchCategory.watch_category!
end
end
end
end