2017-04-04 19:21:37 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FeedInsertWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2017-11-18 00:16:48 +01: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
|
2019-06-25 22:56:32 +02:00
|
|
|
when :direct
|
|
|
|
@account = Account.find(id)
|
2017-11-18 00:16:48 +01:00
|
|
|
end
|
2017-05-10 20:32:05 +02:00
|
|
|
|
|
|
|
check_and_insert
|
2017-11-18 00:16:48 +01:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_and_insert
|
2017-11-18 00:16:48 +01:00
|
|
|
perform_push unless feed_filtered?
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def feed_filtered?
|
2017-11-18 00:16:48 +01:00
|
|
|
# Note: Lists are a variation of home, so the filtering rules
|
|
|
|
# of home apply to both
|
2019-06-25 22:56:32 +02:00
|
|
|
case @type
|
|
|
|
when :home, :list
|
|
|
|
FeedManager.instance.filter?(:home, @status, @follower.id)
|
|
|
|
when :direct
|
|
|
|
FeedManager.instance.filter?(:direct, @status, @account.id)
|
|
|
|
end
|
2017-05-10 20:32:05 +02:00
|
|
|
end
|
2017-04-04 19:21:37 +02:00
|
|
|
|
2017-05-10 20:32:05 +02:00
|
|
|
def perform_push
|
2017-11-18 00:16:48 +01:00
|
|
|
case @type
|
|
|
|
when :home
|
|
|
|
FeedManager.instance.push_to_home(@follower, @status)
|
|
|
|
when :list
|
|
|
|
FeedManager.instance.push_to_list(@list, @status)
|
2019-06-25 22:56:32 +02:00
|
|
|
when :direct
|
|
|
|
FeedManager.instance.push_to_direct(@account, @status)
|
2017-11-18 00:16:48 +01:00
|
|
|
end
|
2017-04-04 19:21:37 +02:00
|
|
|
end
|
|
|
|
end
|