]> cat aescling's git repositories - mastodon.git/blob - app/workers/feed_insert_worker.rb
Bump aws-sdk-s3 from 1.89.0 to 1.91.0 (#15879)
[mastodon.git] / app / workers / feed_insert_worker.rb
1 # frozen_string_literal: true
2
3 class FeedInsertWorker
4 include Sidekiq::Worker
5
6 def perform(status_id, id, type = :home)
7 @type = type.to_sym
8 @status = Status.find(status_id)
9
10 case @type
11 when :home
12 @follower = Account.find(id)
13 when :list
14 @list = List.find(id)
15 @follower = @list.account
16 end
17
18 check_and_insert
19 rescue ActiveRecord::RecordNotFound
20 true
21 end
22
23 private
24
25 def check_and_insert
26 return if feed_filtered?
27
28 perform_push
29 perform_notify if notify?
30 end
31
32 def feed_filtered?
33 case @type
34 when :home
35 FeedManager.instance.filter?(:home, @status, @follower)
36 when :list
37 FeedManager.instance.filter?(:list, @status, @list)
38 end
39 end
40
41 def notify?
42 return false if @type != :home || @status.reblog? || (@status.reply? && @status.in_reply_to_account_id != @status.account_id)
43
44 Follow.find_by(account: @follower, target_account: @status.account)&.notify?
45 end
46
47 def perform_push
48 case @type
49 when :home
50 FeedManager.instance.push_to_home(@follower, @status)
51 when :list
52 FeedManager.instance.push_to_list(@list, @status)
53 end
54 end
55
56 def perform_notify
57 NotifyService.new.call(@follower, :status, @status)
58 end
59 end
This page took 0.081181 seconds and 4 git commands to generate.