FIX: backwards compatibility with stable discourse 2.5.0 (#53)
Few if statements to ensure plugin works with a stable discourse. Completely obsolete once 2.6.0 will become stable
This commit is contained in:
parent
8de0fa9ecf
commit
18794557db
|
@ -8,14 +8,19 @@ export default {
|
|||
withPluginApi("0.8.32", api => {
|
||||
const siteSettings = api.container.lookup("site-settings:main");
|
||||
if (siteSettings.voting_enabled) {
|
||||
const pageSearchController = api.container.lookup(
|
||||
"controller:full-page-search"
|
||||
);
|
||||
pageSearchController.sortOrders.pushObject({
|
||||
name: I18n.t("search.most_votes"),
|
||||
id: 5,
|
||||
term: "order:votes"
|
||||
});
|
||||
// TODO: Remove if check once Discourse 2.6 is stable
|
||||
if (
|
||||
I18n.findTranslation("notifications.votes_released", { locale: "en" })
|
||||
) {
|
||||
const pageSearchController = api.container.lookup(
|
||||
"controller:full-page-search"
|
||||
);
|
||||
pageSearchController.sortOrders.pushObject({
|
||||
name: I18n.t("search.most_votes"),
|
||||
id: 5,
|
||||
term: "order:votes"
|
||||
});
|
||||
}
|
||||
|
||||
api.addNavigationBarItem({
|
||||
name: "votes",
|
||||
|
|
17
plugin.rb
17
plugin.rb
|
@ -102,12 +102,18 @@ after_initialize do
|
|||
add_to_serializer(:basic_category, :can_vote, false) { SiteSetting.voting_enabled }
|
||||
add_to_serializer(:basic_category, :include_can_vote?) { Category.can_vote?(object.id) }
|
||||
|
||||
register_search_advanced_filter(/^min_vote_count:(\d+)$/) do |posts, match|
|
||||
posts.where("(SELECT votes_count FROM discourse_voting_topic_vote_count WHERE discourse_voting_topic_vote_count.topic_id = posts.topic_id) >= ?", match.to_i)
|
||||
# TODO: Remove if check once Discourse 2.6 is stable
|
||||
if respond_to?(:register_search_advanced_filter)
|
||||
register_search_advanced_filter(/^min_vote_count:(\d+)$/) do |posts, match|
|
||||
posts.where("(SELECT votes_count FROM discourse_voting_topic_vote_count WHERE discourse_voting_topic_vote_count.topic_id = posts.topic_id) >= ?", match.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
register_search_advanced_order(:votes) do |posts|
|
||||
posts.reorder("COALESCE((SELECT dvtvc.votes_count FROM discourse_voting_topic_vote_count dvtvc WHERE dvtvc.topic_id = subquery.topic_id), 0) DESC")
|
||||
# TODO: Remove if check once Discourse 2.6 is stable
|
||||
if respond_to?(:register_search_advanced_order)
|
||||
register_search_advanced_order(:votes) do |posts|
|
||||
posts.reorder("COALESCE((SELECT dvtvc.votes_count FROM discourse_voting_topic_vote_count dvtvc WHERE dvtvc.topic_id = subquery.topic_id), 0) DESC")
|
||||
end
|
||||
end
|
||||
|
||||
class ::Category
|
||||
|
@ -227,6 +233,9 @@ after_initialize do
|
|||
|
||||
return if args[:trashed]
|
||||
|
||||
# TODO: Remove once Discourse 2.6 is stable
|
||||
return unless Plugin::Instance.new.respond_to?(:register_search_advanced_filter)
|
||||
|
||||
votes.find_each do |vote|
|
||||
Notification.create!(user_id: vote.user_id,
|
||||
notification_type: Notification.types[:votes_released],
|
||||
|
|
Loading…
Reference in New Issue