diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index ea3a9c8d9..81e2d3573 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -9,6 +9,16 @@ class DText "[quote]\n#{creator_name} said:\n\n#{stripped_body}\n[/quote]\n\n" end + def self.parse_mentions(text) + text = strip_blocks(text.to_s, "quote") + + names = text.scan(MENTION_REGEXP).map do |mention| + mention.gsub(/(?:^\s*@)|(?:[:;,.!?\)\]<>]$)/, "") + end + + names.uniq + end + def self.strip_blocks(string, tag) n = 0 stripped = "" @@ -91,4 +101,3 @@ class DText excerpt end end - diff --git a/app/logical/mentionable.rb b/app/logical/mentionable.rb index c4e1306eb..44bb7fba7 100644 --- a/app/logical/mentionable.rb +++ b/app/logical/mentionable.rb @@ -17,13 +17,8 @@ module Mentionable end def queue_mention_messages - from_id = read_attribute(self.class.mentionable_option(:user_field)) text = read_attribute(self.class.mentionable_option(:message_field)) - text = DText.strip_blocks(text, "quote") - - names = text.scan(DText::MENTION_REGEXP).map do |mention| - mention.gsub!(/(?:^\s*@)|(?:[:;,.!?\)\]<>]$)/, "") - end + names = DText.parse_mentions(text) names.uniq.each do |name| body = self.instance_exec(name, &self.class.mentionable_option(:body)) diff --git a/app/models/comment.rb b/app/models/comment.rb index 0a7d13008..60daac47e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -22,7 +22,6 @@ class Comment < ApplicationRecord attr_accessible :is_sticky, :as => [:moderator, :admin] mentionable( :message_field => :body, - :user_field => :creator_id, :title => lambda {|user_name| "#{creator_name} mentioned you in a comment on post ##{post_id}"}, :body => lambda {|user_name| "@#{creator_name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n"}, ) diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 78e3c7c13..38c4fffe8 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -27,7 +27,6 @@ class ForumPost < ApplicationRecord end mentionable( :message_field => :body, - :user_field => :creator_id, :title => lambda {|user_name| %{#{creator_name} mentioned you in topic ##{topic_id} (#{topic.title})}}, :body => lambda {|user_name| %{@#{creator_name} mentioned you in topic ##{topic_id} ("#{topic.title}":[/forum_topics/#{topic_id}?page=#{forum_topic_page}]):\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n}}, )