Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41ffd718d5 | ||
|
|
cd698ce800 |
@@ -95,17 +95,13 @@ class Notification < ApplicationRecord
|
|||||||
def push_message_title
|
def push_message_title
|
||||||
case notification_type
|
case notification_type
|
||||||
when 'conversation_creation'
|
when 'conversation_creation'
|
||||||
I18n.t('notifications.notification_title.conversation_creation', display_id: conversation.display_id, inbox_name: primary_actor.inbox.name)
|
conversation_creation_message_content
|
||||||
when 'conversation_assignment'
|
when 'conversation_assignment'
|
||||||
I18n.t('notifications.notification_title.conversation_assignment', display_id: conversation.display_id)
|
I18n.t('notifications.notification_title.conversation_assignment', display_id: conversation.display_id)
|
||||||
when 'assigned_conversation_new_message', 'participating_conversation_new_message'
|
when 'assigned_conversation_new_message', 'participating_conversation_new_message'
|
||||||
I18n.t(
|
message_created_message_content
|
||||||
'notifications.notification_title.assigned_conversation_new_message',
|
|
||||||
display_id: conversation.display_id,
|
|
||||||
content: content
|
|
||||||
)
|
|
||||||
when 'conversation_mention'
|
when 'conversation_mention'
|
||||||
"[##{conversation&.display_id}] #{transform_user_mention_content content}"
|
mention_content
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
@@ -115,6 +111,18 @@ class Notification < ApplicationRecord
|
|||||||
primary_actor
|
primary_actor
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def conversation_creation_message_content
|
||||||
|
"#{conversation.messages.first&.sender&.name}: #{content}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_created_message_content
|
||||||
|
"#{secondary_actor&.sender&.name}: #{content}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def mention_content
|
||||||
|
"#{secondary_actor&.sender&.name}: #{transform_user_mention_content(secondary_actor&.content&.truncate_words(10) || '')}"
|
||||||
|
end
|
||||||
|
|
||||||
def content
|
def content
|
||||||
transform_user_mention_content(secondary_actor&.content&.truncate_words(10) || '')
|
transform_user_mention_content(secondary_actor&.content&.truncate_words(10) || '')
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ RSpec.describe Notification do
|
|||||||
|
|
||||||
context 'when push_title is called' do
|
context 'when push_title is called' do
|
||||||
it 'returns appropriate title suited for the notification type conversation_creation' do
|
it 'returns appropriate title suited for the notification type conversation_creation' do
|
||||||
notification = create(:notification, notification_type: 'conversation_creation')
|
conversation = create(:conversation)
|
||||||
expect(notification.push_message_title).to eq "[New conversation] - ##{notification.primary_actor.display_id} has\
|
message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2), conversation: conversation)
|
||||||
been created in #{notification.primary_actor.inbox.name}"
|
notification = create(:notification, notification_type: 'conversation_creation', primary_actor: conversation)
|
||||||
|
expect(notification.push_message_title).to eq "#{message.sender.name}: #{message.content}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns appropriate title suited for the notification type conversation_assignment' do
|
it 'returns appropriate title suited for the notification type conversation_assignment' do
|
||||||
@@ -39,8 +40,7 @@ RSpec.describe Notification do
|
|||||||
notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: message.conversation,
|
notification = create(:notification, notification_type: 'assigned_conversation_new_message', primary_actor: message.conversation,
|
||||||
secondary_actor: message)
|
secondary_actor: message)
|
||||||
|
|
||||||
expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} \
|
expect(notification.push_message_title).to eq "#{message.sender.name}: #{message.content.truncate_words(10)}"
|
||||||
#{message.content.truncate_words(10)}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns appropriate title suited for the notification type assigned_conversation_new_message when attachment message' do
|
it 'returns appropriate title suited for the notification type assigned_conversation_new_message when attachment message' do
|
||||||
@@ -100,8 +100,7 @@ Hey @John, @Alisha Peter can you check this ticket?"
|
|||||||
content: 'Hey [@John](mention://user/1/john), [@Alisha Peter](mention://user/2/alisha) can you check this ticket?'
|
content: 'Hey [@John](mention://user/1/john), [@Alisha Peter](mention://user/2/alisha) can you check this ticket?'
|
||||||
)
|
)
|
||||||
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message.conversation, secondary_actor: message)
|
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message.conversation, secondary_actor: message)
|
||||||
|
expect(notification.push_message_title).to eq "#{message.sender.name}: Hey @John, @Alisha Peter can you check this ticket?"
|
||||||
expect(notification.push_message_title).to eq "[##{message.conversation.display_id}] Hey @John, @Alisha Peter can you check this ticket?"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns appropriate title suited for the notification type conversation_mention if username contains white space' do
|
it 'returns appropriate title suited for the notification type conversation_mention if username contains white space' do
|
||||||
@@ -111,7 +110,7 @@ Hey @John, @Alisha Peter can you check this ticket?"
|
|||||||
content: 'Hey [@John Peter](mention://user/1/john%20K) please check this?'
|
content: 'Hey [@John Peter](mention://user/1/john%20K) please check this?'
|
||||||
)
|
)
|
||||||
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message.conversation, secondary_actor: message)
|
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message.conversation, secondary_actor: message)
|
||||||
expect(notification.push_message_title).to eq "[##{message.conversation.display_id}] Hey @John Peter please check this?"
|
expect(notification.push_message_title).to eq "#{message.sender.name}: Hey @John Peter please check this?"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls remove duplicate notification job' do
|
it 'calls remove duplicate notification job' do
|
||||||
|
|||||||
Reference in New Issue
Block a user