-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplugin.rb
77 lines (67 loc) · 2 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
# name: shadowban
# about: Hide a user's posts from everybody else
# version: 0.0.1
# authors: Michael Howell (notriddle)
# url: https://github.com/notriddle/discourse-shadowban
enabled_site_setting :shadowban_enabled
after_initialize do
module ::DiscourseShadowbanTopicView
def filter_post_types(posts)
result = super(posts)
if SiteSetting.shadowban_show_to_staff && @user&.staff?
result
else
result.where(
'posts.user_id NOT IN (SELECT u.id FROM users u WHERE username_lower IN (?) AND u.id != ?)',
SiteSetting.shadowban_users.split('|'),
@user&.id || 0
)
end
end
end
class ::TopicView
prepend ::DiscourseShadowbanTopicView
end
module ::DiscourseShadowbanTopicQuery
def default_results(options = {})
result = super(options)
if SiteSetting.shadowban_show_to_staff && @user&.staff?
result
else
result.where(
'topics.user_id NOT IN (SELECT u.id FROM users u WHERE username_lower IN (?) AND u.id != ?)',
SiteSetting.shadowban_users.split('|'),
@user&.id || 0
)
end
end
end
class ::TopicQuery
prepend ::DiscourseShadowbanTopicQuery
end
module ::DiscourseShadowbanPostAlerter
def create_notification(user, type, post, opts = {})
if (SiteSetting.shadowban_show_to_staff && user&.staff?) || SiteSetting.shadowban_users.split('|').find_index(post.user&.username_lower).nil?
super(user, type, post, opts)
end
end
end
class ::PostAlerter
prepend ::DiscourseShadowbanPostAlerter
end
module ::DiscourseShadowbanPostCreator
def update_topic_stats
if SiteSetting.shadowban_users.split('|').find_index(@post.user&.username_lower).nil?
super
end
end
def update_user_counts
if SiteSetting.shadowban_users.split('|').find_index(@post.user&.username_lower).nil?
super
end
end
end
class ::PostCreator
prepend ::DiscourseShadowbanPostCreator
end
end