2020-09-07 09:02:04 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-07 08:40:55 +00:00
|
|
|
class PublicFeed
|
2020-09-07 09:02:04 +00:00
|
|
|
# @param [Account] account
|
|
|
|
# @param [Hash] options
|
|
|
|
# @option [Boolean] :with_replies
|
|
|
|
# @option [Boolean] :with_reblogs
|
|
|
|
# @option [Boolean] :local
|
|
|
|
# @option [Boolean] :remote
|
|
|
|
# @option [Boolean] :only_media
|
2022-07-03 05:54:03 +00:00
|
|
|
# @option [Boolean] :without_media
|
|
|
|
# @option [Boolean] :without_bot
|
2020-09-07 09:02:04 +00:00
|
|
|
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)
|
2022-08-23 05:14:23 +00:00
|
|
|
return Status.none if local_only? && account? && !imast? && !mastodon_for_ios? && !mastodon_for_android?
|
2020-06-08 16:34:51 +00:00
|
|
|
|
2020-09-07 09:02:04 +00:00
|
|
|
scope = public_scope
|
|
|
|
|
|
|
|
scope.merge!(without_replies_scope) unless with_replies?
|
|
|
|
scope.merge!(without_reblogs_scope) unless with_reblogs?
|
2022-08-23 05:14:23 +00:00
|
|
|
scope.merge!(local_only_scope) if local_only? && !account?
|
|
|
|
scope.merge!(public_searchable_scope) if local_only? && !account?
|
2020-09-07 09:02:04 +00:00
|
|
|
scope.merge!(remote_only_scope) if remote_only?
|
2019-11-13 22:42:56 +00:00
|
|
|
scope.merge!(domain_only_scope) if domain_only?
|
2020-09-07 09:02:04 +00:00
|
|
|
scope.merge!(account_filters_scope) if account?
|
|
|
|
scope.merge!(media_only_scope) if media_only?
|
2022-07-03 05:54:03 +00:00
|
|
|
scope.merge!(without_media_scope) if without_media?
|
|
|
|
scope.merge!(without_bot_scope) if without_bot?
|
2020-09-07 09:02:04 +00:00
|
|
|
|
|
|
|
scope.cache_ids.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-07 08:40:55 +00:00
|
|
|
attr_reader :account, :options
|
|
|
|
|
2020-09-07 09:02:04 +00:00
|
|
|
def with_reblogs?
|
2021-01-07 08:40:55 +00:00
|
|
|
options[:with_reblogs]
|
2020-09-07 09:02:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def with_replies?
|
2021-01-07 08:40:55 +00:00
|
|
|
options[:with_replies]
|
2020-09-07 09:02:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def local_only?
|
2022-07-03 05:54:03 +00:00
|
|
|
options[:local]
|
2020-06-08 16:34:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def imast?
|
2022-07-03 05:54:03 +00:00
|
|
|
options[:application]&.website == 'https://cinderella-project.github.io/iMast/'
|
2020-06-08 16:34:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def mastodon_for_ios?
|
2022-07-03 05:54:03 +00:00
|
|
|
options[:application]&.name == 'Mastodon for iOS'
|
2020-06-08 16:34:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def mastodon_for_android?
|
2022-07-03 05:54:03 +00:00
|
|
|
options[:application]&.name == 'Mastodon for Android'
|
2020-09-07 09:02:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def remote_only?
|
2021-01-07 08:40:55 +00:00
|
|
|
options[:remote]
|
2020-09-07 09:02:04 +00:00
|
|
|
end
|
|
|
|
|
2019-11-13 22:42:56 +00:00
|
|
|
def domain_only?
|
2022-07-03 05:54:03 +00:00
|
|
|
options[:domain]
|
2019-11-13 22:42:56 +00:00
|
|
|
end
|
|
|
|
|
2020-09-07 09:02:04 +00:00
|
|
|
def account?
|
2021-01-07 08:40:55 +00:00
|
|
|
account.present?
|
2020-09-07 09:02:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def media_only?
|
2021-01-07 08:40:55 +00:00
|
|
|
options[:only_media]
|
2020-09-07 09:02:04 +00:00
|
|
|
end
|
|
|
|
|
2022-07-03 05:54:03 +00:00
|
|
|
def without_media?
|
|
|
|
options[:without_media]
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_bot?
|
|
|
|
options[:without_bot]
|
|
|
|
end
|
|
|
|
|
2019-11-13 22:42:56 +00:00
|
|
|
def domain
|
2022-07-03 05:54:03 +00:00
|
|
|
options[:domain]
|
2019-11-13 22:42:56 +00:00
|
|
|
end
|
|
|
|
|
2020-09-07 09:02:04 +00:00
|
|
|
def public_scope
|
|
|
|
Status.with_public_visibility.joins(:account).merge(Account.without_suspended.without_silenced)
|
|
|
|
end
|
|
|
|
|
|
|
|
def local_only_scope
|
|
|
|
Status.local
|
|
|
|
end
|
|
|
|
|
2022-08-23 05:14:23 +00:00
|
|
|
def public_searchable_scope
|
|
|
|
Status.where(searchability: 'public').or(Status.where(searchability: nil).merge(Account.where(searchability: 'public')))
|
|
|
|
end
|
|
|
|
|
2020-09-07 09:02:04 +00:00
|
|
|
def remote_only_scope
|
|
|
|
Status.remote
|
|
|
|
end
|
|
|
|
|
2019-11-13 22:42:56 +00:00
|
|
|
def domain_only_scope
|
|
|
|
Status.joins(:account).merge(Account.where(domain: domain))
|
|
|
|
end
|
|
|
|
|
2020-09-07 09:02:04 +00:00
|
|
|
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
|
|
|
|
|
2022-07-03 05:54:03 +00:00
|
|
|
def without_media_scope
|
|
|
|
Status.left_joins(:media_attachments).where(media_attachments: {status_id: nil})
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_bot_scope
|
|
|
|
Status.joins(:account).merge(Account.without_bots)
|
|
|
|
end
|
|
|
|
|
2020-09-07 09:02:04 +00:00
|
|
|
def account_filters_scope
|
2021-01-07 08:40:55 +00:00
|
|
|
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?
|
2020-09-07 09:02:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|