about summary refs log tree commit diff
path: root/app/services/post_status_service.rb
blob: 39bbe9f9ef0a0b02e05f36bc6230523727c8fa0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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

    status.mentions.each do |mentioned_account|
      next if mentioned_account.local?
      send_interaction_service.(status.stream_entry, mentioned_account)
    end
  end

  private

  def follow_remote_account_service
    @follow_remote_account_service ||= FollowRemoteAccountService.new
  end

  def send_interaction_service
    @send_interaction_service ||= SendInteractionService.new
  end
end