[verified] Remove Chatwoot Hub push relay
This commit is contained in:
@@ -9,7 +9,6 @@ class Notification::PushNotificationService
|
||||
notification_subscriptions.each do |subscription|
|
||||
send_browser_push(subscription)
|
||||
send_fcm_push(subscription)
|
||||
send_push_via_chatwoot_hub(subscription)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,9 +87,13 @@ class Notification::PushNotificationService
|
||||
end
|
||||
|
||||
def send_fcm_push(subscription)
|
||||
return unless firebase_credentials_present?
|
||||
return unless subscription.fcm?
|
||||
|
||||
unless firebase_credentials_present?
|
||||
Rails.logger.warn('FCM push skipped: Firebase credentials are not configured; no remote push relay is used')
|
||||
return
|
||||
end
|
||||
|
||||
fcm_service = Notification::FcmService.new(
|
||||
GlobalConfigService.load('FIREBASE_PROJECT_ID', nil), GlobalConfigService.load('FIREBASE_CREDENTIALS', nil)
|
||||
)
|
||||
@@ -99,22 +102,10 @@ class Notification::PushNotificationService
|
||||
remove_subscription_if_error(subscription, response)
|
||||
end
|
||||
|
||||
def send_push_via_chatwoot_hub(subscription)
|
||||
return if firebase_credentials_present?
|
||||
return unless chatwoot_hub_enabled?
|
||||
return unless subscription.fcm?
|
||||
|
||||
ChatwootHub.send_push(fcm_options(subscription))
|
||||
end
|
||||
|
||||
def firebase_credentials_present?
|
||||
GlobalConfigService.load('FIREBASE_PROJECT_ID', nil) && GlobalConfigService.load('FIREBASE_CREDENTIALS', nil)
|
||||
end
|
||||
|
||||
def chatwoot_hub_enabled?
|
||||
ActiveModel::Type::Boolean.new.cast(ENV.fetch('ENABLE_PUSH_RELAY_SERVER', true))
|
||||
end
|
||||
|
||||
def remove_subscription_if_error(subscription, response)
|
||||
if JSON.parse(response[:body])['results']&.first&.keys&.include?('error')
|
||||
subscription.destroy!
|
||||
|
||||
@@ -50,13 +50,11 @@ class Notification::PushTestService
|
||||
end
|
||||
|
||||
def test_fcm(subscription)
|
||||
if firebase_credentials_present?
|
||||
test_fcm_direct(subscription)
|
||||
elsif chatwoot_hub_enabled?
|
||||
test_fcm_via_hub(subscription)
|
||||
else
|
||||
result(subscription, 'fcm', :skipped, 'No Firebase credentials and push relay disabled')
|
||||
unless firebase_credentials_present?
|
||||
return result(subscription, 'fcm', :skipped, 'Firebase credentials are not configured; no remote push relay is used')
|
||||
end
|
||||
|
||||
test_fcm_direct(subscription)
|
||||
end
|
||||
|
||||
def test_fcm_direct(subscription)
|
||||
@@ -72,23 +70,10 @@ class Notification::PushTestService
|
||||
result(subscription, 'fcm', :failure, "#{e.class.name}: #{e.message}")
|
||||
end
|
||||
|
||||
def test_fcm_via_hub(subscription)
|
||||
response = ChatwootHub.send_push_with_response(fcm_options(subscription))
|
||||
result(subscription, 'fcm_via_hub', :success, "HTTP #{response.code} — #{response.body}")
|
||||
rescue RestClient::ExceptionWithResponse => e
|
||||
result(subscription, 'fcm_via_hub', :failure, "HTTP #{e.response&.code} — #{e.response&.body}")
|
||||
rescue StandardError => e
|
||||
result(subscription, 'fcm_via_hub', :failure, "#{e.class.name}: #{e.message}")
|
||||
end
|
||||
|
||||
def firebase_credentials_present?
|
||||
GlobalConfigService.load('FIREBASE_PROJECT_ID', nil) && GlobalConfigService.load('FIREBASE_CREDENTIALS', nil)
|
||||
end
|
||||
|
||||
def chatwoot_hub_enabled?
|
||||
ActiveModel::Type::Boolean.new.cast(ENV.fetch('ENABLE_PUSH_RELAY_SERVER', true))
|
||||
end
|
||||
|
||||
def browser_push_payload(subscription)
|
||||
{
|
||||
message: JSON.generate(
|
||||
|
||||
Reference in New Issue
Block a user