feed_insert_worker.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # frozen_string_literal: true
  2. class FeedInsertWorker
  3. include Sidekiq::Worker
  4. def perform(status_id, id, type = :home)
  5. @type = type.to_sym
  6. @status = Status.find(status_id)
  7. case @type
  8. when :home
  9. @follower = Account.find(id)
  10. when :list
  11. @list = List.find(id)
  12. @follower = @list.account
  13. end
  14. check_and_insert
  15. rescue ActiveRecord::RecordNotFound
  16. true
  17. end
  18. private
  19. def check_and_insert
  20. return if feed_filtered?
  21. perform_push
  22. perform_notify if notify?
  23. end
  24. def feed_filtered?
  25. case @type
  26. when :home
  27. FeedManager.instance.filter?(:home, @status, @follower)
  28. when :list
  29. FeedManager.instance.filter?(:list, @status, @list)
  30. end
  31. end
  32. def notify?
  33. return false if @type != :home || @status.reblog? || (@status.reply? && @status.in_reply_to_account_id != @status.account_id)
  34. Follow.find_by(account: @follower, target_account: @status.account)&.notify?
  35. end
  36. def perform_push
  37. case @type
  38. when :home
  39. FeedManager.instance.push_to_home(@follower, @status)
  40. when :list
  41. FeedManager.instance.push_to_list(@list, @status)
  42. end
  43. end
  44. def perform_notify
  45. NotifyService.new.call(@follower, :status, @status)
  46. end
  47. end