diff --git a/app/assets/stylesheets/chat.scss b/app/assets/stylesheets/chat.scss index d82f0a558..393bde756 100644 --- a/app/assets/stylesheets/chat.scss +++ b/app/assets/stylesheets/chat.scss @@ -1114,7 +1114,7 @@ color: gray; width: max-content; } -.comment-mentioned-all { +.mentioned-all { color: rgb(213, 138, 0); } diff --git a/app/models/article.rb b/app/models/article.rb index 0f976f109..c156e90bc 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -689,8 +689,8 @@ class Article < ApplicationRecord def user_mentions_in_markdown return if created_at.present? && created_at.before?(MAX_USER_MENTION_LIVE_AT) - # The "comment-mentioned-user" css is added by Html::Parser#user_link_if_exists - mentions_count = Nokogiri::HTML(processed_html).css(".comment-mentioned-user").size + # The "mentioned-user" css is added by Html::Parser#user_link_if_exists + mentions_count = Nokogiri::HTML(processed_html).css(".mentioned-user").size return if mentions_count <= MAX_USER_MENTIONS errors.add(:base, "You cannot mention more than #{MAX_USER_MENTIONS} users in a post!") diff --git a/app/models/comment.rb b/app/models/comment.rb index 8b807c8e6..999ca143b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -313,8 +313,8 @@ class Comment < ApplicationRecord def user_mentions_in_markdown return if created_at.present? && created_at.before?(MAX_USER_MENTION_LIVE_AT) - # The "comment-mentioned-user" css is added by Html::Parser#user_link_if_exists - mentions_count = Nokogiri::HTML(processed_html).css(".comment-mentioned-user").size + # The "mentioned-user" css is added by Html::Parser#user_link_if_exists + mentions_count = Nokogiri::HTML(processed_html).css(".mentioned-user").size return if mentions_count <= MAX_USER_MENTIONS errors.add(:base, "You cannot mention more than #{MAX_USER_MENTIONS} users in a comment!") diff --git a/app/models/message.rb b/app/models/message.rb index 7725cc770..1f964156e 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -86,11 +86,11 @@ class Message < ApplicationRecord username = mention.delete("@").downcase if User.find_by(username: username) && chat_channel.group? <<~HTML - @#{username} + @#{username} HTML elsif username == "all" && chat_channel.channel_type == "invite_only" <<~HTML - @#{username} + @#{username} HTML else mention diff --git a/app/services/html/parser.rb b/app/services/html/parser.rb index f17340875..832f58f93 100644 --- a/app/services/html/parser.rb +++ b/app/services/html/parser.rb @@ -274,7 +274,7 @@ module Html username = mention.delete("@").downcase if User.find_by(username: username) <<~HTML - @#{username} + @#{username} HTML else mention diff --git a/app/services/mentions/create_all.rb b/app/services/mentions/create_all.rb index 5f79030c5..a3a51ccfa 100644 --- a/app/services/mentions/create_all.rb +++ b/app/services/mentions/create_all.rb @@ -36,9 +36,9 @@ module Mentions end def extract_usernames_from_mentions_in_text - # The "comment-mentioned-user" css is added by Html::Parser#user_link_if_exists + # The "mentioned-user" css is added by Html::Parser#user_link_if_exists doc = Nokogiri::HTML(notifiable.processed_html) - doc.css(".comment-mentioned-user").map do |link| + doc.css(".mentioned-user").map do |link| link.text.delete("@").downcase end end diff --git a/lib/data_update_scripts/20210412183428_resave_all_comment_mentioned_messages.rb b/lib/data_update_scripts/20210412183428_resave_all_comment_mentioned_messages.rb new file mode 100644 index 000000000..7954ea689 --- /dev/null +++ b/lib/data_update_scripts/20210412183428_resave_all_comment_mentioned_messages.rb @@ -0,0 +1,9 @@ +module DataUpdateScripts + class ResaveAllCommentMentionedMessages + def run + # Resave all Messages that previously relied upon the `.comment-mentioned-user` CSS, + # which was renamed in https://github.com/forem/forem/pull/13263 to `.mentioned-user`. + Message.find_each(&:save) + end + end +end diff --git a/lib/data_update_scripts/20210412185444_resave_all_comment_mentioned_comments.rb b/lib/data_update_scripts/20210412185444_resave_all_comment_mentioned_comments.rb new file mode 100644 index 000000000..c684777cc --- /dev/null +++ b/lib/data_update_scripts/20210412185444_resave_all_comment_mentioned_comments.rb @@ -0,0 +1,9 @@ +module DataUpdateScripts + class ResaveAllCommentMentionedComments + def run + # Resave all Comments that previously relied upon the `.comment-mentioned-user` CSS, + # which was renamed in https://github.com/forem/forem/pull/13263 to `.mentioned-user`. + Comment.find_each(&:save) + end + end +end diff --git a/lib/data_update_scripts/20210412185449_resave_all_comment_mentioned_articles.rb b/lib/data_update_scripts/20210412185449_resave_all_comment_mentioned_articles.rb new file mode 100644 index 000000000..b949f24fd --- /dev/null +++ b/lib/data_update_scripts/20210412185449_resave_all_comment_mentioned_articles.rb @@ -0,0 +1,9 @@ +module DataUpdateScripts + class ResaveAllCommentMentionedArticles + def run + # Resave all Articles that previously relied upon the `.comment-mentioned-user` CSS, + # which was renamed in https://github.com/forem/forem/pull/13263 to `.mentioned-user`. + Article.published.find_each(&:save) + end + end +end diff --git a/spec/services/markdown_processor/parser_spec.rb b/spec/services/markdown_processor/parser_spec.rb index 3d4fb0c15..6a46b8770 100644 --- a/spec/services/markdown_processor/parser_spec.rb +++ b/spec/services/markdown_processor/parser_spec.rb @@ -190,7 +190,7 @@ RSpec.describe MarkdownProcessor::Parser, type: :service do DOC result = generate_and_parse_markdown(mention) - expected_result = "
@#{user.username} one two, " \
"@#{user.username}\n three four:
@#{user.username}