2020-09-07 05:02:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class TagFeed < PublicFeed
|
2024-02-06 14:23:36 -05:00
|
|
|
LIMIT_PER_MODE = (ENV['MAX_FEED_HASHTAGS'] || 4).to_i
|
2020-09-07 05:02:04 -04:00
|
|
|
|
|
|
|
# @param [Tag] tag
|
|
|
|
# @param [Account] account
|
|
|
|
# @param [Hash] options
|
|
|
|
# @option [Enumerable<String>] :any
|
|
|
|
# @option [Enumerable<String>] :all
|
|
|
|
# @option [Enumerable<String>] :none
|
|
|
|
# @option [Boolean] :local
|
|
|
|
# @option [Boolean] :remote
|
|
|
|
# @option [Boolean] :only_media
|
|
|
|
def initialize(tag, account, options = {})
|
2021-01-07 03:40:55 -05:00
|
|
|
@tag = tag
|
|
|
|
super(account, options)
|
2020-09-07 05:02:04 -04:00
|
|
|
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)
|
|
|
|
scope = public_scope
|
|
|
|
|
2020-09-08 10:01:55 -04:00
|
|
|
scope.merge!(without_local_only_scope) unless local_account?
|
2020-09-07 05:02:04 -04:00
|
|
|
scope.merge!(tagged_with_any_scope)
|
|
|
|
scope.merge!(tagged_with_all_scope)
|
|
|
|
scope.merge!(tagged_with_none_scope)
|
|
|
|
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.cache_ids.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def tagged_with_any_scope
|
2021-01-07 03:40:55 -05:00
|
|
|
Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(options[:any])))
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tagged_with_all_scope
|
2021-01-07 03:40:55 -05:00
|
|
|
Status.group(:id).tagged_with_all(tags_for(options[:all]))
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tagged_with_none_scope
|
2021-01-07 03:40:55 -05:00
|
|
|
Status.group(:id).tagged_with_none(tags_for(options[:none]))
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tags_for(names)
|
2020-09-23 10:01:54 -04:00
|
|
|
Tag.matching_name(Array(names).take(LIMIT_PER_MODE)).pluck(:id) if names.present?
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
end
|