about summary refs log tree commit diff
path: root/app/services/post_status_service.rb
blob: e8fc6cdefc49d4bc004f838d2ae5aa4c528ba8e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class PostStatusService < BaseService
  def call(account, text, in_reply_to = nil)
    status = account.statuses.create!(text: text, thread: in_reply_to)

    status.text.scan(Account::MENTION_RE).each do |match|
      next if match.first.split('@').size == 1
      username, domain = match.first.split('@')
      local_account = Account.find_by(username: username, domain: domain)
      next unless local_account.nil?
      follow_remote_account_service.("acct:#{match.first}")
    end
  end

  private

  def follow_remote_account_service
    @follow_remote_account_service ||= FollowRemoteAccountService.new
  end
end