Add public_unlisted scope as status privacy

This commit is contained in:
KMY 2023-03-05 13:24:31 +09:00
parent b049e7c502
commit ed3abf4f2a
35 changed files with 64 additions and 39 deletions

View file

@ -35,7 +35,7 @@ class AccountStatusesFilter
if suspended?
Status.none
elsif anonymous?
account.statuses.where(visibility: %i(public unlisted))
account.statuses.where(visibility: %i(public unlisted public_unlisted))
elsif author?
account.statuses.all # NOTE: #merge! does not work without the #all
elsif blocked?
@ -48,7 +48,7 @@ class AccountStatusesFilter
def filtered_scope
scope = account.statuses.left_outer_joins(:mentions)
scope.merge!(scope.where(visibility: follower? ? %i(public unlisted private) : %i(public unlisted)).or(scope.where(mentions: { account_id: current_account.id })).group(Status.arel_table[:id]))
scope.merge!(scope.where(visibility: follower? ? %i(public unlisted public_unlisted private) : %i(public unlisted public_unlisted)).or(scope.where(mentions: { account_id: current_account.id })).group(Status.arel_table[:id]))
scope.merge!(filtered_reblogs_scope) if reblogs_may_occur?
scope

View file

@ -14,7 +14,7 @@ class Admin::StatusFilter
end
def results
scope = @account.statuses.where(visibility: [:public, :unlisted])
scope = @account.statuses.where(visibility: [:public, :unlisted, :public_unlisted])
params.each do |key, value|
next if %w(page report_id).include?(key.to_s)

View file

@ -57,7 +57,7 @@ class Announcement < ApplicationRecord
@statuses ||= if status_ids.nil?
[]
else
Status.where(id: status_ids, visibility: [:public, :unlisted])
Status.where(id: status_ids, visibility: [:public, :unlisted, :public_unlisted])
end
end

View file

@ -12,7 +12,7 @@ module StatusThreadingConcern
end
def self_replies(limit)
account.statuses.where(in_reply_to_id: id, visibility: [:public, :unlisted]).reorder(id: :asc).limit(limit)
account.statuses.where(in_reply_to_id: id, visibility: [:public, :unlisted, :public_unlisted]).reorder(id: :asc).limit(limit)
end
private

View file

@ -45,7 +45,7 @@ class FeaturedTag < ApplicationRecord
end
def decrement(deleted_status_id)
update(statuses_count: [0, statuses_count - 1].max, last_status_at: account.statuses.where(visibility: %i(public unlisted)).tagged_with(tag).where.not(id: deleted_status_id).select(:created_at).first&.created_at)
update(statuses_count: [0, statuses_count - 1].max, last_status_at: account.statuses.where(visibility: %i(public unlisted public_unlisted)).tagged_with(tag).where.not(id: deleted_status_id).select(:created_at).first&.created_at)
end
private
@ -59,8 +59,8 @@ class FeaturedTag < ApplicationRecord
end
def reset_data
self.statuses_count = account.statuses.where(visibility: %i(public unlisted)).tagged_with(tag).count
self.last_status_at = account.statuses.where(visibility: %i(public unlisted)).tagged_with(tag).select(:created_at).first&.created_at
self.statuses_count = account.statuses.where(visibility: %i(public unlisted public_unlisted)).tagged_with(tag).count
self.last_status_at = account.statuses.where(visibility: %i(public unlisted public_unlisted)).tagged_with(tag).select(:created_at).first&.created_at
end
def validate_featured_tags_limit

View file

@ -25,6 +25,7 @@ class PublicFeed
scope.merge!(without_reblogs_scope) unless with_reblogs?
scope.merge!(local_only_scope) if local_only?
scope.merge!(remote_only_scope) if remote_only?
scope.merge!(global_timeline_only_scope) if global_timeline?
scope.merge!(account_filters_scope) if account?
scope.merge!(media_only_scope) if media_only?
scope.merge!(language_scope) if account&.chosen_languages.present?
@ -52,6 +53,10 @@ class PublicFeed
options[:remote]
end
def global_timeline?
!options[:remote] && !options[:local]
end
def account?
account.present?
end
@ -72,6 +77,10 @@ class PublicFeed
Status.remote
end
def global_timeline_only_scope
Status.with_global_timeline_visibility.joins(:account).merge(Account.without_suspended.without_silenced)
end
def without_replies_scope
Status.without_replies
end

View file

@ -51,7 +51,7 @@ class Status < ApplicationRecord
update_index('statuses', :proper)
enum visibility: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4 }, _suffix: :visibility
enum visibility: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4, public_unlisted: 10 }, _suffix: :visibility
belongs_to :application, class_name: 'Doorkeeper::Application', optional: true
@ -99,7 +99,8 @@ class Status < ApplicationRecord
scope :with_accounts, ->(ids) { where(id: ids).includes(:account) }
scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
scope :without_reblogs, -> { where(statuses: { reblog_of_id: nil }) }
scope :with_public_visibility, -> { where(visibility: :public) }
scope :with_public_visibility, -> { where(visibility: [:public, :public_unlisted]) }
scope :with_global_timeline_visibility, -> { where(visibility: [:public]) }
scope :tagged_with, ->(tag_ids) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag_ids }) }
scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) }
scope :including_silenced_accounts, -> { left_outer_joins(:account).where.not(accounts: { silenced_at: nil }) }
@ -232,7 +233,7 @@ class Status < ApplicationRecord
end
def distributable?
public_visibility? || unlisted_visibility?
public_visibility? || unlisted_visibility? || public_unlisted_visibility?
end
alias sign? distributable?