Skip to content

Commit

Permalink
Fix rubocop error and cleanup Status.as_direct_timeline a little
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed May 21, 2024
1 parent d3136e6 commit edf6ca5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,33 +344,33 @@ def as_direct_timeline(account, limit = 20, max_id = nil, since_id = nil)

# _from_me part does not require any timeline filters
query_from_me = where(account_id: account.id)
.where(Status.arel_table[:visibility].eq(3))
.direct_visibility
.limit(limit)
.order('statuses.id DESC')
.order(id: :desc)

# _to_me part requires mute and block filter.
# FIXME: may we check mutes.hide_notifications?
query_to_me = Status
.direct_visibility
.joins(:mentions)
.merge(Mention.where(account_id: account.id))
.where(Status.arel_table[:visibility].eq(3))
.where(mentions: { account_id: account.id })
.limit(limit)
.order('mentions.status_id DESC')
.not_excluded_by_account(account)

if max_id.present?
query_from_me = query_from_me.where('statuses.id < ?', max_id)
query_to_me = query_to_me.where('mentions.status_id < ?', max_id)
query_from_me = query_from_me.where(id: ...max_id)
query_to_me = query_to_me.where(mentions: { status_id: ...max_id })
end

if since_id.present?
query_from_me = query_from_me.where('statuses.id > ?', since_id)
query_to_me = query_to_me.where('mentions.status_id > ?', since_id)
end

# returns ActiveRecord.Relation
items = (query_from_me.select(:id).to_a + query_to_me.select(:id).to_a).uniq(&:id).sort_by(&:id).reverse.take(limit)
Status.where(id: items.map(&:id))
# TODO: use a single query?
ids = (query_from_me.pluck(:id) + query_to_me.pluck(:id)).sort.uniq.reverse.take(limit)
Status.where(id: ids)
end

def favourites_map(status_ids, account_id)
Expand Down

0 comments on commit edf6ca5

Please sign in to comment.