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.

63 lines
1.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. # frozen_string_literal: true
  2. class TagsController < ApplicationController
  3. PAGE_SIZE = 20
  4. before_action :set_body_classes
  5. before_action :set_instance_presenter
  6. def show
  7. @tag = Tag.find_by!(name: params[:id].downcase)
  8. respond_to do |format|
  9. format.html do
  10. serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer)
  11. @initial_state_json = serializable_resource.to_json
  12. end
  13. format.rss do
  14. @statuses = HashtagQueryService.new.call(@tag, params.slice(:any, :all, :none)).limit(PAGE_SIZE)
  15. @statuses = cache_collection(@statuses, Status)
  16. render xml: RSS::TagSerializer.render(@tag, @statuses)
  17. end
  18. format.json do
  19. @statuses = HashtagQueryService.new.call(@tag, params.slice(:any, :all, :none), current_account, params[:local])
  20. .paginate_by_max_id(PAGE_SIZE, params[:max_id])
  21. @statuses = cache_collection(@statuses, Status)
  22. render json: collection_presenter,
  23. serializer: ActivityPub::CollectionSerializer,
  24. adapter: ActivityPub::Adapter,
  25. content_type: 'application/activity+json'
  26. end
  27. end
  28. end
  29. private
  30. def set_body_classes
  31. @body_classes = 'with-modals'
  32. end
  33. def set_instance_presenter
  34. @instance_presenter = InstancePresenter.new
  35. end
  36. def collection_presenter
  37. ActivityPub::CollectionPresenter.new(
  38. id: tag_url(@tag, params.slice(:any, :all, :none)),
  39. type: :ordered,
  40. size: @tag.statuses.count,
  41. items: @statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s) }
  42. )
  43. end
  44. def initial_state_params
  45. {
  46. settings: {},
  47. token: current_session&.token,
  48. }
  49. end
  50. end