unlisted & private hashtags

staging
multiple creatures 2019-02-10 23:38:29 +00:00
parent a7aa2544e4
commit 1636a4e8ae
1 changed files with 18 additions and 1 deletions

View File

@ -93,6 +93,8 @@ class Status < ApplicationRecord
scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') }
scope :reblogs, -> { where('statuses.reblog_of_id IS NOT NULL') } # all reblogs
scope :with_public_visibility, -> { where(visibility: :public) }
scope :public_browsable, -> { where(visibility: [:public, :unlisted]) }
scope :visible_to, ->(account) { where(visibility: [:public, :unlisted]).or(where(account: [account] + account.following).where(visibility: :private)) }
scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) }
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 }) }
@ -371,7 +373,8 @@ class Status < ApplicationRecord
end
def as_tag_timeline(tag, account = nil, local_only = false)
query = timeline_scope(local_only).tagged_with(tag)
query = (account.nil?) ? browsable_timeline_scope(local_only) : user_timeline_scope(account, local_only)
query = query.tagged_with(tag)
apply_timeline_filters(query, account, local_only)
end
@ -454,6 +457,20 @@ class Status < ApplicationRecord
end
end
def browsable_timeline_scope(local_only = false)
starting_scope = local_only ? Status.local : Status
starting_scope
.public_browsable
.without_reblogs
end
def user_timeline_scope(account, local_only = false)
starting_scope = local_only ? Status.local : Status
starting_scope
.visible_to(account)
.without_reblogs
end
def apply_timeline_filters(query, account, local_only)
if account.nil?
filter_timeline_default(query)