Class: Collavre::PushNotificationJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/collavre/push_notification_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(user_id, message:, link: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/collavre/push_notification_job.rb', line 5

def perform(user_id, message:, link: nil)
  tokens = Device.where(user_id: user_id).pluck(:fcm_token)
  return if tokens.empty?

  service = Rails.application.config.x.fcm_service
  project_id = Rails.application.config.x.fcm_project_id

  if service && project_id
    tokens.each do |token|
      send_v1(service, project_id, token, message, link)
    end
  elsif (client = Rails.application.config.x.fcm_client)
    client.send(tokens, {
      notification: {
        title: "새 알림",
        body: message,
        click_action: link
      }
    })
  end
end