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.

64 lines
1.8 KiB

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