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.

35 lines
1.0 KiB

  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. return unless status.local?
  8. status.text.scan(Account::MENTION_RE).each do |match|
  9. username, domain = match.first.split('@')
  10. mentioned_account = Account.find_by(username: username, domain: domain)
  11. if mentioned_account.nil?
  12. mentioned_account = follow_remote_account_service.("#{match.first}")
  13. end
  14. mentioned_account.mentions.first_or_create(status: status)
  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. end
  21. private
  22. def follow_remote_account_service
  23. @follow_remote_account_service ||= FollowRemoteAccountService.new
  24. end
  25. def send_interaction_service
  26. @send_interaction_service ||= SendInteractionService.new
  27. end
  28. end