The code powering m.abunchtell.com https://m.abunchtell.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

47 satır
1.3 KiB

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