mentions: factor out mention parsing to DText.parse_mentions.

This commit is contained in:
evazion
2017-08-04 22:30:11 -05:00
parent 40e006f7cb
commit 4c54e18c6d
4 changed files with 11 additions and 9 deletions

View File

@@ -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

View File

@@ -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))