link_feed.rb 1007 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. class LinkFeed < PublicFeed
  3. # @param [PreviewCard] preview_card
  4. # @param [Account] account
  5. # @param [Hash] options
  6. def initialize(preview_card, account, options = {})
  7. @preview_card = preview_card
  8. super(account, options)
  9. end
  10. # @param [Integer] limit
  11. # @param [Integer] max_id
  12. # @param [Integer] since_id
  13. # @param [Integer] min_id
  14. # @return [Array<Status>]
  15. def get(limit, max_id = nil, since_id = nil, min_id = nil)
  16. scope = public_scope
  17. scope.merge!(discoverable)
  18. scope.merge!(attached_to_preview_card)
  19. scope.merge!(account_filters_scope) if account?
  20. scope.merge!(language_scope) if account&.chosen_languages.present?
  21. scope.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
  22. end
  23. private
  24. def attached_to_preview_card
  25. Status.joins(:preview_cards_status).where(preview_cards_status: { preview_card_id: @preview_card.id })
  26. end
  27. def discoverable
  28. Account.discoverable
  29. end
  30. end