chore: Change the notification text for mention notification type (#2534)
This commit is contained in:
parent
044b6872a4
commit
8027c69c1c
5 changed files with 44 additions and 4 deletions
6
app/helpers/message_format_helper.rb
Normal file
6
app/helpers/message_format_helper.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
module MessageFormatHelper
|
||||
include RegexHelper
|
||||
def transform_user_mention_content(message_content)
|
||||
message_content.gsub(MENTION_REGEX, '\1')
|
||||
end
|
||||
end
|
|
@ -23,6 +23,7 @@
|
|||
#
|
||||
|
||||
class Notification < ApplicationRecord
|
||||
include MessageFormatHelper
|
||||
belongs_to :account
|
||||
belongs_to :user
|
||||
|
||||
|
@ -73,7 +74,7 @@ class Notification < ApplicationRecord
|
|||
content: primary_actor.content&.truncate_words(10)
|
||||
)
|
||||
when 'conversation_mention'
|
||||
I18n.t('notifications.notification_title.conversation_mention', display_id: conversation.display_id, name: secondary_actor.name)
|
||||
"[##{conversation.display_id}] #{transform_user_mention_content primary_actor.content}"
|
||||
else
|
||||
''
|
||||
end
|
||||
|
|
|
@ -5,4 +5,5 @@ module RegexHelper
|
|||
# valid unicode letter, unicode number, underscore, hyphen
|
||||
# shouldn't start with a underscore or hyphen
|
||||
UNICODE_CHARACTER_NUMBER_HYPHEN_UNDERSCORE = Regexp.new('\A[\p{L}\p{N}]+[\p{L}\p{N}_-]+\Z')
|
||||
MENTION_REGEX = Regexp.new('\[(@[\w_. ]+)\]\(mention://(?:user|team)/\d+/(.*?)+\)')
|
||||
end
|
||||
|
|
11
spec/helpers/message_format_helper_spec.rb
Normal file
11
spec/helpers/message_format_helper_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe MessageFormatHelper, type: :helper do
|
||||
describe '#transform_user_mention_content' do
|
||||
context 'when transform_user_mention_content called' do
|
||||
it 'return transormed text correctly' do
|
||||
expect(helper.transform_user_mention_content('[@john](mention://user/1/John%20K), check this ticket')).to eq '@john, check this ticket'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -50,11 +50,32 @@ RSpec.describe Notification do
|
|||
end
|
||||
|
||||
it 'returns appropriate title suited for the notification type conversation_mention' do
|
||||
message = create(:message, sender: create(:user))
|
||||
message = create(:message, sender: create(:user), content: 'Hey [@John](mention://user/1/john), can you check this ticket?')
|
||||
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message, secondary_actor: message.sender)
|
||||
|
||||
expect(notification.push_message_title).to eq "You have been mentioned in conversation [ID - #{message.conversation.display_id}] \
|
||||
by #{message.sender.name}"
|
||||
expect(notification.push_message_title).to eq "[##{message.conversation.display_id}] Hey @John, can you check this ticket?"
|
||||
end
|
||||
|
||||
it 'returns appropriate title suited for the notification type conversation_mention having multiple mentions' do
|
||||
message = create(
|
||||
:message, sender:
|
||||
create(:user),
|
||||
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, secondary_actor: message.sender)
|
||||
|
||||
expect(notification.push_message_title).to eq "[##{message.conversation.display_id}] 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
|
||||
message = create(
|
||||
:message, sender:
|
||||
create(:user),
|
||||
content: 'Hey [@John Peter](mention://user/1/john%20K) please check this?'
|
||||
)
|
||||
notification = create(:notification, notification_type: 'conversation_mention', primary_actor: message, secondary_actor: message.sender)
|
||||
|
||||
expect(notification.push_message_title).to eq "[##{message.conversation.display_id}] Hey @John Peter please check this?"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue