Compare commits

...
Author SHA1 Message Date
Muhsin Keloth 41ffd718d5 fixes 2024-02-22 10:49:57 +05:30
Muhsin Keloth cd698ce800 chore: push title 2024-02-14 16:11:21 +05:30
2 changed files with 22 additions and 15 deletions
+15 -7
View File
@@ -95,17 +95,13 @@ class Notification < ApplicationRecord
def push_message_title
case notification_type
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'
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
)
message_created_message_content
when 'conversation_mention'
"[##{conversation&.display_id}] #{transform_user_mention_content content}"
mention_content
else
''
end
@@ -115,6 +111,18 @@ class Notification < ApplicationRecord
primary_actor
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
transform_user_mention_content(secondary_actor&.content&.truncate_words(10) || '')
end
+7 -8
View File
@@ -23,9 +23,10 @@ RSpec.describe Notification do
context 'when push_title is called' do
it 'returns appropriate title suited for the notification type conversation_creation' do
notification = create(:notification, notification_type: 'conversation_creation')
expect(notification.push_message_title).to eq "[New conversation] - ##{notification.primary_actor.display_id} has\
been created in #{notification.primary_actor.inbox.name}"
conversation = create(:conversation)
message = create(:message, sender: create(:user), content: Faker::Lorem.paragraphs(number: 2), conversation: conversation)
notification = create(:notification, notification_type: 'conversation_creation', primary_actor: conversation)
expect(notification.push_message_title).to eq "#{message.sender.name}: #{message.content}"
end
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,
secondary_actor: message)
expect(notification.push_message_title).to eq "[New message] - ##{notification.conversation.display_id} \
#{message.content.truncate_words(10)}"
expect(notification.push_message_title).to eq "#{message.sender.name}: #{message.content.truncate_words(10)}"
end
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?'
)
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, @Alisha Peter can you check this ticket?"
expect(notification.push_message_title).to eq "#{message.sender.name}: Hey @John, @Alisha Peter can you check this ticket?"
end
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?'
)
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
it 'calls remove duplicate notification job' do