闭社主体 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.

42 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_remote(username, domain)
  11. if mentioned_account.nil? && !domain.nil?
  12. begin
  13. mentioned_account = follow_remote_account_service.("#{match.first}")
  14. rescue Goldfinger::Error, HTTP::Error
  15. mentioned_account = nil
  16. end
  17. end
  18. next if mentioned_account.nil?
  19. mentioned_account.mentions.where(status: status).first_or_create(status: status)
  20. end
  21. status.mentions.each do |mention|
  22. mentioned_account = mention.account
  23. if mentioned_account.local?
  24. NotificationMailer.mention(mentioned_account, status).deliver_later
  25. else
  26. NotificationWorker.perform_async(status.stream_entry.id, mentioned_account.id)
  27. end
  28. end
  29. end
  30. private
  31. def follow_remote_account_service
  32. @follow_remote_account_service ||= FollowRemoteAccountService.new
  33. end
  34. end