2017-04-04 13:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FeedInsertWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2017-11-17 18:16:48 -05:00
|
|
|
def perform(status_id, id, type = :home)
|
|
|
|
@type = type.to_sym
|
|
|
|
@status = Status.find(status_id)
|
|
|
|
|
|
|
|
case @type
|
|
|
|
when :home
|
|
|
|
@follower = Account.find(id)
|
|
|
|
when :list
|
|
|
|
@list = List.find(id)
|
|
|
|
@follower = @list.account
|
|
|
|
end
|
2017-05-10 14:32:05 -04:00
|
|
|
|
|
|
|
check_and_insert
|
2017-11-17 18:16:48 -05:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
2017-05-10 14:32:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_and_insert
|
2017-11-17 18:16:48 -05:00
|
|
|
perform_push unless feed_filtered?
|
2017-05-10 14:32:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def feed_filtered?
|
2020-09-07 21:41:16 -04:00
|
|
|
case @type
|
|
|
|
when :home
|
|
|
|
FeedManager.instance.filter?(:home, @status, @follower)
|
|
|
|
when :list
|
|
|
|
FeedManager.instance.filter?(:list, @status, @list)
|
|
|
|
end
|
2017-05-10 14:32:05 -04:00
|
|
|
end
|
2017-04-04 13:21:37 -04:00
|
|
|
|
2017-05-10 14:32:05 -04:00
|
|
|
def perform_push
|
2017-11-17 18:16:48 -05:00
|
|
|
case @type
|
|
|
|
when :home
|
|
|
|
FeedManager.instance.push_to_home(@follower, @status)
|
|
|
|
when :list
|
|
|
|
FeedManager.instance.push_to_list(@list, @status)
|
|
|
|
end
|
2017-04-04 13:21:37 -04:00
|
|
|
end
|
|
|
|
end
|