process_mentions_service.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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.mentions.each do |mention|
  18. mentioned_account = mention.account
  19. if mentioned_account.local?
  20. NotificationMailer.mention(mentioned_account, status).deliver_later
  21. else
  22. NotificationWorker.perform_async(status.stream_entry.id, mentioned_account.id)
  23. end
  24. end
  25. end
  26. private
  27. def follow_remote_account_service
  28. @follow_remote_account_service ||= FollowRemoteAccountService.new
  29. end
  30. end