You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. # frozen_string_literal: true
  2. class TagsController < ApplicationController
  3. include SignatureVerification
  4. PAGE_SIZE = 20
  5. PAGE_SIZE_MAX = 200
  6. layout 'public'
  7. before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
  8. before_action :authenticate_user!, if: :whitelist_mode?
  9. before_action :set_tag
  10. before_action :set_local
  11. before_action :set_body_classes
  12. before_action :set_instance_presenter
  13. skip_before_action :require_functional!, unless: :whitelist_mode?
  14. def show
  15. respond_to do |format|
  16. format.html do
  17. expires_in 0, public: true
  18. end
  19. format.rss do
  20. expires_in 0, public: true
  21. limit = params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
  22. @statuses = HashtagQueryService.new.call(@tag, filter_params, nil, @local).limit(limit)
  23. @statuses = cache_collection(@statuses, Status)
  24. render xml: RSS::TagSerializer.render(@tag, @statuses)
  25. end
  26. format.json do
  27. expires_in 3.minutes, public: public_fetch_mode?
  28. @statuses = HashtagQueryService.new.call(@tag, filter_params, current_account, @local).paginate_by_max_id(PAGE_SIZE, params[:max_id])
  29. @statuses = cache_collection(@statuses, Status)
  30. render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
  31. end
  32. end
  33. end
  34. private
  35. def set_tag
  36. @tag = Tag.usable.find_normalized!(params[:id])
  37. end
  38. def set_local
  39. @local = truthy_param?(:local)
  40. end
  41. def set_body_classes
  42. @body_classes = 'with-modals'
  43. end
  44. def set_instance_presenter
  45. @instance_presenter = InstancePresenter.new
  46. end
  47. def collection_presenter
  48. ActivityPub::CollectionPresenter.new(
  49. id: tag_url(@tag, filter_params),
  50. type: :ordered,
  51. size: @tag.statuses.count,
  52. items: @statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s) }
  53. )
  54. end
  55. def filter_params
  56. params.slice(:any, :all, :none).permit(:any, :all, :none)
  57. end
  58. end