FIX: backwards compatibility with stable discourse 2.5.0 (#53)

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

diff --git a/assets/javascripts/discourse/initializers/discourse-voting.js.es6 b/assets/javascripts/discourse/initializers/discourse-voting.js.es6
index 864cc42..b2b3319 100644
--- a/assets/javascripts/discourse/initializers/discourse-voting.js.es6
+++ b/assets/javascripts/discourse/initializers/discourse-voting.js.es6
@@ -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",
diff --git a/plugin.rb b/plugin.rb
index c2316ae..c1dc7ef 100755
--- a/plugin.rb
+++ b/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],

GitHub sha: 18794557

This commit appears in #53 which was merged by lis2.