Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from https://github.com/mastodon/mastodon, unmodified.
122 lines
2.8 KiB
Ruby
122 lines
2.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PublicFeed
|
|
# @param [Account] account
|
|
# @param [Hash] options
|
|
# @option [Boolean] :with_replies
|
|
# @option [Boolean] :with_reblogs
|
|
# @option [Boolean] :local
|
|
# @option [Boolean] :remote
|
|
# @option [Boolean] :only_media
|
|
def initialize(account, options = {})
|
|
@account = account
|
|
@options = options
|
|
end
|
|
|
|
# @param [Integer] limit
|
|
# @param [Integer] max_id
|
|
# @param [Integer] since_id
|
|
# @param [Integer] min_id
|
|
# @return [Array<Status>]
|
|
def get(limit, max_id = nil, since_id = nil, min_id = nil)
|
|
return [] if incompatible_feed_settings?
|
|
|
|
scope = public_scope
|
|
|
|
scope.merge!(without_replies_scope) unless with_replies?
|
|
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!(account_filters_scope) if account?
|
|
scope.merge!(media_only_scope) if media_only?
|
|
scope.merge!(language_scope) if account&.chosen_languages.present?
|
|
|
|
scope.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :account, :options
|
|
|
|
def incompatible_feed_settings?
|
|
(local_only? && !user_has_access_to_feed?(local_feed_setting)) || (remote_only? && !user_has_access_to_feed?(remote_feed_setting))
|
|
end
|
|
|
|
def user_has_access_to_feed?(setting)
|
|
case setting
|
|
when 'public'
|
|
true
|
|
when 'authenticated'
|
|
@account&.user&.functional?
|
|
when 'disabled'
|
|
@account&.user&.can?(:view_feeds)
|
|
end
|
|
end
|
|
|
|
def with_reblogs?
|
|
options[:with_reblogs]
|
|
end
|
|
|
|
def with_replies?
|
|
options[:with_replies]
|
|
end
|
|
|
|
def local_feed_setting
|
|
Setting.local_live_feed_access
|
|
end
|
|
|
|
def remote_feed_setting
|
|
Setting.remote_live_feed_access
|
|
end
|
|
|
|
def local_only?
|
|
(options[:local] && !options[:remote]) || !user_has_access_to_feed?(remote_feed_setting)
|
|
end
|
|
|
|
def remote_only?
|
|
(options[:remote] && !options[:local]) || !user_has_access_to_feed?(local_feed_setting)
|
|
end
|
|
|
|
def account?
|
|
account.present?
|
|
end
|
|
|
|
def media_only?
|
|
options[:only_media]
|
|
end
|
|
|
|
def public_scope
|
|
Status.public_visibility.joins(:account).merge(Account.without_suspended.without_silenced)
|
|
end
|
|
|
|
def local_only_scope
|
|
Status.local
|
|
end
|
|
|
|
def remote_only_scope
|
|
Status.remote
|
|
end
|
|
|
|
def without_replies_scope
|
|
Status.without_replies
|
|
end
|
|
|
|
def without_reblogs_scope
|
|
Status.without_reblogs
|
|
end
|
|
|
|
def media_only_scope
|
|
Status.joins(:media_attachments).group(:id)
|
|
end
|
|
|
|
def language_scope
|
|
Status.where(language: account.chosen_languages)
|
|
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?
|
|
end
|
|
end
|
|
end
|