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

46 lines
1.4 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. next if status.private_visibility? && (!mentioned_account.following?(status.account) || !mentioned_account.local?)
  25. if mentioned_account.local?
  26. NotifyService.new.call(mentioned_account, mention)
  27. else
  28. NotificationWorker.perform_async(status.stream_entry.id, mentioned_account.id)
  29. end
  30. end
  31. end
  32. private
  33. def follow_remote_account_service
  34. @follow_remote_account_service ||= FollowRemoteAccountService.new
  35. end
  36. end