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.
 
 
 
 

71 lines
1.8 KiB

  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. skip_before_action :require_functional!
  12. def show
  13. respond_to do |format|
  14. format.html do
  15. expires_in 0, public: true
  16. end
  17. format.rss do
  18. expires_in 0, public: true
  19. @statuses = HashtagQueryService.new.call(@tag, filter_params).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, filter_params, 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, filter_params),
  44. type: :ordered,
  45. size: @tag.statuses.count,
  46. items: @statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s) }
  47. )
  48. end
  49. def filter_params
  50. params.slice(:any, :all, :none).permit(:any, :all, :none)
  51. end
  52. end