Chore: FCM Push Fixes (#934)

This commit is contained in:
Sojan Jose
2020-06-09 17:42:18 +05:30
committed by GitHub
parent 40481f6462
commit 8b022311c0
6 changed files with 92 additions and 21 deletions

View File

@@ -29,21 +29,9 @@ class Notification::PushNotificationService
@conversation ||= notification.primary_actor
end
def push_message_title
if notification.notification_type == 'conversation_creation'
return "A new conversation [ID -#{conversation.display_id}] has been created in #{conversation.inbox.name}"
end
if notification.notification_type == 'conversation_assignment'
return "A new conversation [ID -#{conversation.display_id}] has been assigned to you."
end
''
end
def push_message
{
title: push_message_title,
title: notification.push_message_title,
tag: "#{notification.notification_type}_#{conversation.display_id}",
url: push_url
}
@@ -78,11 +66,14 @@ class Notification::PushNotificationService
return unless subscription.fcm?
fcm = FCM.new(ENV['FCM_SERVER_KEY'])
options = { "notification": {
"title": notification.notification_type.titleize,
"body": push_message_title,
"notification": notification.to_json
} }
options = {
"notification": {
"title": notification.notification_type.titleize,
"body": notification.push_message_title
},
"data": { notification: notification.push_event_data.to_json }
}
response = fcm.send([subscription.subscription_attributes['push_token']], options)
subscription.destroy! if JSON.parse(response[:body])['results']&.first&.keys&.include?('error')
end