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.

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