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.

59 lines
1.2 KiB

  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