diff options
author | Starfall <us@starfall.systems> | 2020-09-14 13:49:06 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2020-09-14 13:49:06 -0500 |
commit | bc32e736fbd7c6afd59e619c885fa80ab637324a (patch) | |
tree | afc04eaa04aeb45b56c378bdc474428d6fdcc813 /app/models/status.rb | |
parent | fd0b806603dbd632d259d06af789c7195c7264dc (diff) | |
parent | afa753a890197b188ddf7ba6a8493d4fe361d956 (diff) |
Merge branch 'glitch' into main
Diffstat (limited to 'app/models/status.rb')
-rw-r--r-- | app/models/status.rb | 66 |
1 files changed, 1 insertions, 65 deletions
diff --git a/app/models/status.rb b/app/models/status.rb index 594ae98c0..8495927af 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -89,12 +89,12 @@ class Status < ApplicationRecord scope :recent, -> { reorder(id: :desc) } scope :remote, -> { where(local: false).where.not(uri: nil) } scope :local, -> { where(local: true).or(where(uri: nil)) } - 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 IS NULL') } scope :with_public_visibility, -> { where(visibility: :public) } scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) } + scope :in_chosen_languages, ->(account) { where(language: nil).or where(language: account.chosen_languages) } 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 }) } scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) } @@ -330,23 +330,6 @@ class Status < ApplicationRecord end end - def as_public_timeline(account = nil, local_only = false) - query = timeline_scope(local_only) - query = query.without_replies unless Setting.show_replies_in_public_timelines - - apply_timeline_filters(query, account, [:local, true].include?(local_only)) - end - - def as_tag_timeline(tag, account = nil, local_only = false) - query = timeline_scope(local_only).tagged_with(tag) - - apply_timeline_filters(query, account, local_only) - end - - def as_outbox_timeline(account) - where(account: account, visibility: :public) - end - def favourites_map(status_ids, account_id) Favourite.select('status_id').where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true } end @@ -423,53 +406,6 @@ class Status < ApplicationRecord status&.distributable? ? status : nil end.compact end - - private - - def timeline_scope(scope = false) - starting_scope = case scope - when :local, true - Status.local - when :remote - Status.remote - else - Status - end - starting_scope = starting_scope.with_public_visibility - if Setting.show_reblogs_in_public_timelines - starting_scope - else - starting_scope.without_reblogs - end - end - - def apply_timeline_filters(query, account, local_only) - if account.nil? - filter_timeline_default(query) - else - filter_timeline_for_account(query, account, local_only) - end - end - - def filter_timeline_for_account(query, account, local_only) - query = query.not_excluded_by_account(account) - query = query.not_domain_blocked_by_account(account) unless local_only - query = query.in_chosen_languages(account) if account.chosen_languages.present? - query.merge(account_silencing_filter(account)) - end - - def filter_timeline_default(query) - query.not_local_only.excluding_silenced_accounts - end - - def account_silencing_filter(account) - if account.silenced? - including_myself = left_outer_joins(:account).where(account_id: account.id).references(:accounts) - excluding_silenced_accounts.or(including_myself) - else - excluding_silenced_accounts - end - end end def marked_local_only? |