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.

33 lines
1011 B

  1. class ProcessMentionsService < BaseService
  2. # Scan status for mentions and fetch remote mentioned users, create
  3. # local mention pointers, send Salmon notifications to mentioned
  4. # remote users
  5. # @param [Status] status
  6. def call(status)
  7. status.text.scan(Account::MENTION_RE).each do |match|
  8. username, domain = match.first.split('@')
  9. local_account = Account.find_by(username: username, domain: domain)
  10. if local_account.nil?
  11. local_account = follow_remote_account_service.("acct:#{match.first}")
  12. end
  13. local_account.mentions.first_or_create(status: status)
  14. end
  15. status.mentions.each do |mentioned_account|
  16. next if mentioned_account.local?
  17. send_interaction_service.(status.stream_entry, mentioned_account)
  18. end
  19. end
  20. private
  21. def follow_remote_account_service
  22. @follow_remote_account_service ||= FollowRemoteAccountService.new
  23. end
  24. def send_interaction_service
  25. @send_interaction_service ||= SendInteractionService.new
  26. end
  27. end