-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.rb
35 lines (32 loc) · 1.05 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
# name: discourse-unsolved-filter
# about: Creates an /unsolved route to display all unsolved topics
# version: 0.1
# authors: Osama Sayegh
# url: https://github.com/OsamaSayegh/discourse-unsolved-filter
Discourse.filters << :unsolved
Discourse.anonymous_filters << :unsolved
after_initialize do
TopicQuery.class_eval do
def list_unsolved
create_list(:unsolved) do |topics|
topics = topics.where("topics.id NOT IN (
SELECT tc.topic_id
FROM topic_custom_fields tc
WHERE tc.name = 'accepted_answer_post_id' AND tc.value IS NOT NULL
)").where("topics.id NOT IN (
SELECT cats.topic_id
FROM categories cats WHERE cats.topic_id IS NOT NULL
)")
if !SiteSetting.allow_solved_on_all_topics
topics = topics.where("topics.category_id IN (
SELECT ccf.category_id
FROM category_custom_fields ccf
WHERE ccf.name = 'enable_accepted_answers' AND
ccf.value = 'true'
)")
end
topics
end
end
end
end