forked from discourse/discourse-watch-category-mcneel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.rb
84 lines (68 loc) · 4.02 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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!
announcements_category = Category.find_by_slug("announcements")
namati_staff_group = Group.find_by_name("namati_staff")
return if announcements_category.nil? || namati_staff_group.nil?
namati_staff_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], announcements_category.id) unless watched_categories.include?(announcements_category.id)
end
leadership_category = Category.find_by_slug("leadership")
namati_leadership_group = Group.find_by_name("namati_leadership")
return if leadership_category.nil? || namati_leadership_group.nil?
namati_leadership_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], leadership_category.id) unless watched_categories.include?(leadership_category.id)
end
ngc_category = Category.find_by_slug("ngc")
network_ngc_group = Group.find_by_name("network_ngc")
return if ngc_category.nil? || network_ngc_group.nil?
network_ngc_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], ngc_category.id) unless watched_categories.include?(ngc_category.id)
end
culture_category = Category.find_by_slug("culture")
namati_culture_group = Group.find_by_name("namati_culture")
return if culture_category.nil? || namati_culture_group.nil?
namati_culture_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], culture_category.id) unless watched_categories.include?(culture_category.id)
end
visionoutcome_category = Category.find_by_slug("visionoutcome")
namati_visionoutcome_group = Group.find_by_name("namati_visionoutcome")
return if visionoutcome_category.nil? || namati_visionoutcome_group.nil?
namati_visionoutcome_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], visionoutcome_category.id) unless watched_categories.include?(visionoutcome_category.id)
end
assessingopp_category = Category.find_by_slug("assessingopp")
namati_assessingopp_group = Group.find_by_name("namati_assessingopp")
return if assessingopp_category.nil? || namati_assessingopp_group.nil?
namati_assessingopp_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], assessingopp_category.id) unless watched_categories.include?(assessingopp_category.id)
end
scale_category = Category.find_by_slug("scale")
namati_scale_group = Group.find_by_name("namati_scale")
return if scale_category.nil? || namati_scale_group.nil?
namati_scale_group.users.each do |user|
watched_categories = CategoryUser.lookup(user, :watching).pluck(:category_id)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], scale_category.id) unless watched_categories.include?(scale_category.id)
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