diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 2 | ||||
-rw-r--r-- | app/models/status.rb | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 66345b5ab..2cbec488b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -14,6 +14,8 @@ class Account < ActiveRecord::Base has_many :following, through: :active_relationships, source: :target_account has_many :followers, through: :passive_relationships, source: :account + MENTION_RE = /(?:^|\W)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i + def follow!(other_account) self.active_relationships.first_or_create!(target_account: other_account) end diff --git a/app/models/status.rb b/app/models/status.rb index be616dce6..80719140e 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -51,6 +51,17 @@ class Status < ActiveRecord::Base m << thread.account if reply? m << reblog.account if reblog? + unless reblog? + self.text.scan(Account::MENTION_RE).each do |match| + uri = match.first + username = uri.split('@').first + domain = uri.split('@').size == 2 ? uri.split('@').last : nil + account = Account.find_by(username: username, domain: domain) + + m << account unless account.nil? + end + end + m end |