~cytrogen/masto-fe

ref: 86c9c5afa045b9e2cfa41c15db63ad97d58954c1 masto-fe/app/models/direct_feed.rb -rw-r--r-- 881 bytes
86c9c5af — Claire Merge commit '40ba6e119b7457161fd43b449875d0fb9d473c1a' into glitch-soc/merge-upstream 2 years ago
                                                                                
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
# frozen_string_literal: true

class DirectFeed < Feed
  include Redisable

  def initialize(account)
    @account = account
    super(:direct, account.id)
  end

  def get(limit, max_id = nil, since_id = nil, min_id = nil)
    unless redis.exists("account:#{@account.id}:regeneration")
      statuses = super
      return statuses unless statuses.empty?
    end
    from_database(limit, max_id, since_id, min_id)
  end

  private

  # TODO: _min_id is not actually handled by `as_direct_timeline`
  def from_database(limit, max_id, since_id, _min_id)
    loop do
      statuses = Status.as_direct_timeline(@account, limit, max_id, since_id)
      return statuses if statuses.empty?

      max_id = statuses.last.id
      statuses = statuses.reject { |status| FeedManager.instance.filter?(:direct, status, @account) }
      return statuses unless statuses.empty?
    end
  end
end