Class: PushNotificationSender

Inherits:
Object
  • Object
show all
Defined in:
app/services/push_notification_sender.rb

Constant Summary collapse

REQUIRED_KEYS =
%i[title body].freeze
OPTIONAL_KEYS =
%i[click_action sound android_channel_id icon].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notification) ⇒ PushNotificationSender

Returns a new instance of PushNotificationSender.



9
10
11
# File 'app/services/push_notification_sender.rb', line 9

def initialize(notification)
  @notification = notification
end

Instance Attribute Details

#notificationObject (readonly)

Returns the value of attribute notification.



4
5
6
# File 'app/services/push_notification_sender.rb', line 4

def notification
  @notification
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/push_notification_sender.rb', line 13

def run
  return if notification.receiver.device_ids.blank?
  return if notification.delivered_with?(:fcm)
  return unless REQUIRED_KEYS.all? { |key| notification.respond_to?(key) }

  fcm_client.send(
    notification.receiver.device_ids,
    options
  )

  notification.mark_delivered_with(:fcm)
end