You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
888 B

  1. class PostStatusService < BaseService
  2. def call(account, text, in_reply_to = nil)
  3. status = account.statuses.create!(text: text, thread: in_reply_to)
  4. status.text.scan(Account::MENTION_RE).each do |match|
  5. next if match.first.split('@').size == 1
  6. username, domain = match.first.split('@')
  7. local_account = Account.find_by(username: username, domain: domain)
  8. next unless local_account.nil?
  9. follow_remote_account_service.("acct:#{match.first}")
  10. end
  11. status.mentions.each do |mentioned_account|
  12. next if mentioned_account.local?
  13. send_interaction_service.(status.stream_entry, mentioned_account)
  14. end
  15. end
  16. private
  17. def follow_remote_account_service
  18. @follow_remote_account_service ||= FollowRemoteAccountService.new
  19. end
  20. def send_interaction_service
  21. @send_interaction_service ||= SendInteractionService.new
  22. end
  23. end