The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

36 lines
1.1 KiB

  1. class PostStatusService < BaseService
  2. # Post a text status update, fetch and notify remote users mentioned
  3. # @param [Account] account Account from which to post
  4. # @param [String] text Message
  5. # @param [Status] in_reply_to Optional status to reply to
  6. # @return [Status]
  7. def call(account, text, in_reply_to = nil)
  8. status = account.statuses.create!(text: text, thread: in_reply_to)
  9. status.text.scan(Account::MENTION_RE).each do |match|
  10. next if match.first.split('@').size == 1
  11. username, domain = match.first.split('@')
  12. local_account = Account.find_by(username: username, domain: domain)
  13. next unless local_account.nil?
  14. follow_remote_account_service.("acct:#{match.first}")
  15. end
  16. status.mentions.each do |mentioned_account|
  17. next if mentioned_account.local?
  18. send_interaction_service.(status.stream_entry, mentioned_account)
  19. end
  20. status
  21. end
  22. private
  23. def follow_remote_account_service
  24. @follow_remote_account_service ||= FollowRemoteAccountService.new
  25. end
  26. def send_interaction_service
  27. @send_interaction_service ||= SendInteractionService.new
  28. end
  29. end