This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2017-04-04 19:21:37 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FeedInsertWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2017-05-10 20:32:05 +02:00
|
|
|
attr_reader :status, :follower
|
|
|
|
|
2017-04-04 19:21:37 +02:00
|
|
|
def perform(status_id, follower_id)
|
2017-05-10 20:32:05 +02: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 19:21:37 +02:00
|
|
|
|
2017-05-10 20:32:05 +02:00
|
|
|
def perform_push
|
2017-04-04 19:21:37 +02:00
|
|
|
FeedManager.instance.push(:home, follower, status)
|
|
|
|
end
|
|
|
|
end
|