闭社主体 forked from https://github.com/tootsuite/mastodon
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.

44 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class ProcessMentionsService < BaseService
  3. # Scan status for mentions and fetch remote mentioned users, create
  4. # local mention pointers, send Salmon notifications to mentioned
  5. # remote users
  6. # @param [Status] status
  7. def call(status)
  8. return unless status.local?
  9. status.text.scan(Account::MENTION_RE).each do |match|
  10. username, domain = match.first.split('@')
  11. mentioned_account = Account.find_remote(username, domain)
  12. if mentioned_account.nil? && !domain.nil?
  13. begin
  14. mentioned_account = follow_remote_account_service.call(match.first.to_s)
  15. rescue Goldfinger::Error, HTTP::Error
  16. mentioned_account = nil
  17. end
  18. end
  19. next if mentioned_account.nil?
  20. mentioned_account.mentions.where(status: status).first_or_create(status: status)
  21. end
  22. status.mentions.each do |mention|
  23. mentioned_account = mention.account
  24. if mentioned_account.local?
  25. NotificationMailer.mention(mentioned_account, status).deliver_later unless mentioned_account.blocking?(status.account)
  26. else
  27. NotificationWorker.perform_async(status.stream_entry.id, mentioned_account.id)
  28. end
  29. end
  30. end
  31. private
  32. def follow_remote_account_service
  33. @follow_remote_account_service ||= FollowRemoteAccountService.new
  34. end
  35. end