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.

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