2017-04-04 10:21:37 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FeedInsertWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2017-05-10 11:32:05 -07:00
|
|
|
attr_reader :status, :follower
|
|
|
|
|
2017-04-04 10:21:37 -07:00
|
|
|
def perform(status_id, follower_id)
|
2017-05-10 11:32:05 -07:00
|
|
|
@status = Status.find_by(id: status_id)
|
|
|
|
@follower = Account.find_by(id: follower_id)
|
|
|
|
|
|
|
|
check_and_insert
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_and_insert
|
|
|
|
if records_available?
|
|
|
|
perform_push unless feed_filtered?
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def records_available?
|
|
|
|
status.present? && follower.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def feed_filtered?
|
|
|
|
FeedManager.instance.filter?(:home, status, follower.id)
|
|
|
|
end
|
2017-04-04 10:21:37 -07:00
|
|
|
|
2017-05-10 11:32:05 -07:00
|
|
|
def perform_push
|
2017-04-04 10:21:37 -07:00
|
|
|
FeedManager.instance.push(:home, follower, status)
|
|
|
|
end
|
|
|
|
end
|