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.

41 lines
1.2 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? && !domain.nil?
  12. mentioned_account = follow_remote_account_service.("#{match.first}")
  13. next if mentioned_account.nil?
  14. end
  15. mentioned_account.mentions.where(status: status).first_or_create(status: status)
  16. end
  17. status.mentioned_accounts.each do |mention|
  18. mentioned_account = mention.account
  19. if mentioned_account.local?
  20. NotificationMailer.mention(mentioned_account, status).deliver_later
  21. else
  22. send_interaction_service.(status.stream_entry, mentioned_account)
  23. end
  24. end
  25. end
  26. private
  27. def follow_remote_account_service
  28. @follow_remote_account_service ||= FollowRemoteAccountService.new
  29. end
  30. def send_interaction_service
  31. @send_interaction_service ||= SendInteractionService.new
  32. end
  33. end