From a8af37b3347b5763b70fb42010f8f833536e931e Mon Sep 17 00:00:00 2001 From: merefield Date: Sun, 24 Sep 2023 10:03:38 +0100 Subject: [PATCH] remove redundant sub client check --- lib/custom_wizard/subscription.rb | 34 +++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index ee72b7f8..4c4d841d 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -105,24 +105,22 @@ class CustomWizard::Subscription :product_slug def initialize - if CustomWizard::Subscription.client_installed? - result = DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard") + result = DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard") - if result&.any? - ids_and_slugs = result.subscriptions.map do |subscription| - { - id: subscription.product_id, - slug: result.products[subscription.product_id] - } - end - - id_and_slug = ids_and_slugs.sort do |a, b| - PRODUCT_HIERARCHY.index(b[:slug]) - PRODUCT_HIERARCHY.index(a[:slug]) - end.first - - @product_id = id_and_slug[:id] - @product_slug = id_and_slug[:slug] + if result&.any? + ids_and_slugs = result.subscriptions.map do |subscription| + { + id: subscription.product_id, + slug: result.products[subscription.product_id] + } end + + id_and_slug = ids_and_slugs.sort do |a, b| + PRODUCT_HIERARCHY.index(b[:slug]) - PRODUCT_HIERARCHY.index(a[:slug]) + end.first + + @product_id = id_and_slug[:id] + @product_slug = id_and_slug[:slug] end @product_slug ||= ENV["CUSTOM_WIZARD_PRODUCT_SLUG"] @@ -176,10 +174,6 @@ class CustomWizard::Subscription product_slug === "community" end - def self.client_installed? - defined?(DiscourseSubscriptionClient) == 'constant' && DiscourseSubscriptionClient.class == Module - end - def self.subscribed? new.subscribed? end