From 9c4ce9af3553aa68fcad3f7ca2faaaa95c9de7d4 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Thu, 9 Sep 2021 13:59:42 +0530 Subject: [PATCH] chore: Strip unnecessary data from push payload (#2924) --- app/models/notification.rb | 10 ++++++++++ app/services/notification/push_notification_service.rb | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 752d03100b57..a4d9f8799760 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -60,6 +60,16 @@ def push_event_data } end + def fcm_push_data + { + id: id, + notification_type: notification_type, + primary_actor_id: primary_actor_id, + primary_actor_type: primary_actor_type, + primary_actor: primary_actor.push_event_data.slice(:conversation_id) + } + end + # TODO: move to a data presenter def push_message_title case notification_type diff --git a/app/services/notification/push_notification_service.rb b/app/services/notification/push_notification_service.rb index c98792ec7439..9c45ee74b690 100644 --- a/app/services/notification/push_notification_service.rb +++ b/app/services/notification/push_notification_service.rb @@ -94,9 +94,10 @@ def fcm_options { notification: { title: notification.notification_type.titleize, - body: notification.push_message_title + body: notification.push_message_title, + sound: 'default' }, - data: { notification: notification.push_event_data.to_json }, + data: { notification: notification.fcm_push_data.to_json }, collapse_key: "chatwoot_#{notification.primary_actor_type.downcase}_#{notification.primary_actor_id}" } end