where i deviate from standard mastodon assets
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.

tags_controller.rb 1.8KB

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