From c0cd4770ab323d1990c67807e92a6982a652d3e5 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 24 Oct 2024 13:07:25 +0200 Subject: [PATCH] Update subscription_data handling logic --- .../subscriptions.rb | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/discourse_subscription_client/subscriptions.rb b/lib/discourse_subscription_client/subscriptions.rb index eab0cbf..d8a657f 100644 --- a/lib/discourse_subscription_client/subscriptions.rb +++ b/lib/discourse_subscription_client/subscriptions.rb @@ -54,24 +54,20 @@ def update_supplier(supplier) return (supplier.deactivate_all_subscriptions! && @result.connection_error(supplier)) if response.nil? subscription_data = @result.retrieve_subscriptions(supplier, response) - return supplier.deactivate_all_subscriptions! if @result.errors.any? + return supplier.deactivate_all_subscriptions! if subscription_data.blank? # deactivate any of the supplier's subscriptions not retrieved from supplier - if supplier.subscriptions.present? - supplier.subscriptions.each do |subscription| - has_match = false - subscription_data.each do |data| - if data_matches_subscription(data, subscription) - data.subscription = subscription - has_match = true - end + supplier.subscriptions.each do |subscription| + has_match = false + subscription_data.each do |data| + if data_matches_subscription(data, subscription) + data.subscription = subscription + has_match = true end - subscription.deactivate! unless has_match end + subscription.deactivate! unless has_match end - return @result.no_subscriptions(supplier) if subscription_data.blank? - subscription_data.each do |data| if data.subscription.present? data.subscription.update(subscribed: true)