feat: Revamp the notification title and content (#8988)
This commit is contained in:
@@ -70,7 +70,8 @@ class Notification < ApplicationRecord
|
||||
}
|
||||
if primary_actor.present?
|
||||
payload[:primary_actor] = primary_actor&.push_event_data
|
||||
payload[:push_message_title] = push_message_title
|
||||
# TODO: Rename push_message_title to push_message_body
|
||||
payload[:push_message_title] = push_message_body
|
||||
end
|
||||
payload
|
||||
end
|
||||
@@ -93,13 +94,20 @@ class Notification < ApplicationRecord
|
||||
when 'conversation_assignment'
|
||||
I18n.t('notifications.notification_title.conversation_assignment', display_id: conversation.display_id)
|
||||
when 'assigned_conversation_new_message', 'participating_conversation_new_message'
|
||||
I18n.t(
|
||||
'notifications.notification_title.assigned_conversation_new_message',
|
||||
display_id: conversation.display_id,
|
||||
content: content
|
||||
)
|
||||
I18n.t('notifications.notification_title.assigned_conversation_new_message', display_id: conversation.display_id)
|
||||
when 'conversation_mention'
|
||||
"[##{conversation&.display_id}] #{transform_user_mention_content content}"
|
||||
I18n.t('notifications.notification_title.conversation_mention', display_id: conversation.display_id)
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
def push_message_body
|
||||
case notification_type
|
||||
when 'conversation_creation'
|
||||
message_body(conversation.messages.first)
|
||||
when 'assigned_conversation_new_message', 'participating_conversation_new_message', 'conversation_assignment', 'conversation_mention'
|
||||
message_body(secondary_actor)
|
||||
else
|
||||
''
|
||||
end
|
||||
@@ -109,11 +117,28 @@ class Notification < ApplicationRecord
|
||||
primary_actor
|
||||
end
|
||||
|
||||
def content
|
||||
transform_user_mention_content(secondary_actor&.content&.truncate_words(10) || '')
|
||||
private
|
||||
|
||||
def message_body(actor)
|
||||
sender_name = sender_name(actor)
|
||||
content = message_content(actor)
|
||||
"#{sender_name}: #{content}"
|
||||
end
|
||||
|
||||
private
|
||||
def sender_name(actor)
|
||||
actor.try(:sender)&.name || ''
|
||||
end
|
||||
|
||||
def message_content(actor)
|
||||
content = actor.try(:content)
|
||||
attachments = actor.try(:attachments)
|
||||
|
||||
if content.present?
|
||||
transform_user_mention_content(content.truncate_words(10))
|
||||
else
|
||||
attachments.present? ? I18n.t('notifications.attachment') : I18n.t('notifications.no_content')
|
||||
end
|
||||
end
|
||||
|
||||
def process_notification_delivery
|
||||
Notification::PushNotificationJob.perform_later(self) if user_subscribed_to_notification?('push')
|
||||
|
||||
@@ -93,8 +93,8 @@ class Notification::PushNotificationService
|
||||
def fcm_options
|
||||
{
|
||||
notification: {
|
||||
title: notification.notification_type.titleize,
|
||||
body: notification.push_message_title,
|
||||
title: notification.push_message_title,
|
||||
body: notification.push_message_body,
|
||||
sound: 'default'
|
||||
},
|
||||
android: { priority: 'high' },
|
||||
|
||||
Reference in New Issue
Block a user