mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-24 13:35:07 +01:00
Public timeline to exclude users you blocked
This commit is contained in:
parent
769b1ebbe0
commit
427ba27641
@ -55,7 +55,7 @@ class Api::V1::StatusesController < ApiController
|
||||
end
|
||||
|
||||
def public
|
||||
@statuses = Status.with_includes.with_counters.order('id desc').paginate_by_max_id(20, params[:max_id], params[:since_id]).to_a
|
||||
@statuses = Status.as_public_timeline(current_user.account).paginate_by_max_id(20, params[:max_id], params[:since_id]).to_a
|
||||
render action: :index
|
||||
end
|
||||
end
|
||||
|
@ -18,6 +18,8 @@ class Status < ApplicationRecord
|
||||
validates :text, presence: true, length: { maximum: 500 }, if: proc { |s| s.local? && !s.reblog? }
|
||||
validates :reblog, uniqueness: { scope: :account, message: 'of status already exists' }, if: 'reblog?'
|
||||
|
||||
default_scope { order('id desc') }
|
||||
|
||||
scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') }
|
||||
scope :with_includes, -> { includes(:account, :media_attachments, :stream_entry, mentions: :account, reblog: [:account, mentions: :account], thread: :account) }
|
||||
|
||||
@ -83,6 +85,10 @@ class Status < ApplicationRecord
|
||||
where(id: Mention.where(account: account).pluck(:status_id)).with_includes.with_counters
|
||||
end
|
||||
|
||||
def self.as_public_timeline(account)
|
||||
where.not(account_id: account.blocking).with_includes.with_counters
|
||||
end
|
||||
|
||||
def self.favourites_map(status_ids, account_id)
|
||||
Favourite.where(status_id: status_ids).where(account_id: account_id).map { |f| [f.status_id, true] }.to_h
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user