2017-04-05 02:21:37 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FeedInsertWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2017-11-18 08:16:48 +09: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-26 05:56:32 +09:00
|
|
|
when :direct
|
|
|
|
@account = Account.find(id)
|
2017-11-18 08:16:48 +09:00
|
|
|
end
|
2017-05-11 03:32:05 +09:00
|
|
|
|
|
|
|
check_and_insert
|
2017-11-18 08:16:48 +09:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
2017-05-11 03:32:05 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_and_insert
|
2020-09-19 00:26:45 +09:00
|
|
|
return if feed_filtered?
|
|
|
|
|
|
|
|
perform_push
|
|
|
|
perform_notify if notify?
|
2017-05-11 03:32:05 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def feed_filtered?
|
2019-06-26 05:56:32 +09:00
|
|
|
case @type
|
2020-09-08 10:41:16 +09:00
|
|
|
when :home
|
|
|
|
FeedManager.instance.filter?(:home, @status, @follower)
|
|
|
|
when :list
|
|
|
|
FeedManager.instance.filter?(:list, @status, @list)
|
2019-06-26 05:56:32 +09:00
|
|
|
when :direct
|
2020-09-08 23:01:55 +09:00
|
|
|
FeedManager.instance.filter?(:direct, @status, @account)
|
2019-06-26 05:56:32 +09:00
|
|
|
end
|
2017-05-11 03:32:05 +09:00
|
|
|
end
|
2017-04-05 02:21:37 +09:00
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
def notify?
|
|
|
|
return false if @type != :home || @status.reblog? || (@status.reply? && @status.in_reply_to_account_id != @status.account_id)
|
|
|
|
|
|
|
|
Follow.find_by(account: @follower, target_account: @status.account)&.notify?
|
|
|
|
end
|
|
|
|
|
2017-05-11 03:32:05 +09:00
|
|
|
def perform_push
|
2017-11-18 08:16:48 +09:00
|
|
|
case @type
|
|
|
|
when :home
|
|
|
|
FeedManager.instance.push_to_home(@follower, @status)
|
|
|
|
when :list
|
|
|
|
FeedManager.instance.push_to_list(@list, @status)
|
2019-06-26 05:56:32 +09:00
|
|
|
when :direct
|
|
|
|
FeedManager.instance.push_to_direct(@account, @status)
|
2017-11-18 08:16:48 +09:00
|
|
|
end
|
2017-04-05 02:21:37 +09:00
|
|
|
end
|
2020-09-19 00:26:45 +09:00
|
|
|
|
|
|
|
def perform_notify
|
|
|
|
NotifyService.new.call(@follower, :status, @status)
|
|
|
|
end
|
2017-04-05 02:21:37 +09:00
|
|
|
end
|