about summary refs log tree commit diff
path: root/app/lib/status_reach_finder.rb
blob: 35b191dadb0bc777d2a4f7570dc8ad7e98e07933 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

class StatusReachFinder
  def initialize(status)
    @status = status
  end

  def inboxes
    Account.where(id: reached_account_ids).inboxes
  end

  private

  def reached_account_ids
    [
      replied_to_account_id,
      reblog_of_account_id,
      mentioned_account_ids,
      reblogs_account_ids,
      favourites_account_ids,
      replies_account_ids,
    ].tap do |arr|
      arr.flatten!
      arr.compact!
      arr.uniq!
    end
  end

  def replied_to_account_id
    @status.in_reply_to_account_id
  end

  def reblog_of_account_id
    @status.reblog.account_id if @status.reblog?
  end

  def mentioned_account_ids
    @status.mentions.pluck(:account_id)
  end

  def reblogs_account_ids
    @status.reblogs.pluck(:account_id)
  end

  def favourites_account_ids
    @status.favourites.pluck(:account_id)
  end

  def replies_account_ids
    @status.replies.pluck(:account_id)
  end
end