The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

60 lines
1.7 KiB

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