diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-10-05 03:48:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 03:48:06 +0200 |
commit | 9f65909f42c14d1e56c5f916eb76b156709ac147 (patch) | |
tree | 134f577aafb52c6aeee91b3b51c87eab4e0ba5ca /app/models | |
parent | d2528b26b6da34f34b5d7a392e263428d3c09d69 (diff) |
Change public timelines to be filtered by current locale by default (#19291)
In the absence of an opt-in to multiple specific languages in the preferences, it makes more sense to filter by the user's presumed language only (interface language or `lang` override)
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/public_feed.rb | 13 | ||||
-rw-r--r-- | app/models/status.rb | 1 | ||||
-rw-r--r-- | app/models/tag_feed.rb | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/app/models/public_feed.rb b/app/models/public_feed.rb index 5e4c3e1ce..2cf9206d2 100644 --- a/app/models/public_feed.rb +++ b/app/models/public_feed.rb @@ -8,6 +8,7 @@ class PublicFeed # @option [Boolean] :local # @option [Boolean] :remote # @option [Boolean] :only_media + # @option [String] :locale def initialize(account, options = {}) @account = account @options = options @@ -27,6 +28,7 @@ class PublicFeed scope.merge!(remote_only_scope) if remote_only? scope.merge!(account_filters_scope) if account? scope.merge!(media_only_scope) if media_only? + scope.merge!(language_scope) scope.cache_ids.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id) end @@ -83,10 +85,19 @@ class PublicFeed Status.joins(:media_attachments).group(:id) end + def language_scope + if account&.chosen_languages.present? + Status.where(language: account.chosen_languages) + elsif @options[:locale].present? + Status.where(language: @options[:locale]) + else + Status.all + end + end + def account_filters_scope Status.not_excluded_by_account(account).tap do |scope| scope.merge!(Status.not_domain_blocked_by_account(account)) unless local_only? - scope.merge!(Status.in_chosen_languages(account)) if account.chosen_languages.present? end end end diff --git a/app/models/status.rb b/app/models/status.rb index 7eff990aa..de958aaf3 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -95,7 +95,6 @@ class Status < ApplicationRecord scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') } scope :with_public_visibility, -> { where(visibility: :public) } scope :tagged_with, ->(tag_ids) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag_ids }) } - 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) } diff --git a/app/models/tag_feed.rb b/app/models/tag_feed.rb index b8cd63557..58216bddc 100644 --- a/app/models/tag_feed.rb +++ b/app/models/tag_feed.rb @@ -12,6 +12,7 @@ class TagFeed < PublicFeed # @option [Boolean] :local # @option [Boolean] :remote # @option [Boolean] :only_media + # @option [String] :locale def initialize(tag, account, options = {}) @tag = tag super(account, options) @@ -32,6 +33,7 @@ class TagFeed < PublicFeed scope.merge!(remote_only_scope) if remote_only? scope.merge!(account_filters_scope) if account? scope.merge!(media_only_scope) if media_only? + scope.merge!(language_scope) scope.cache_ids.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id) end |