mastodon/app/controllers/tags_controller.rb

70 lines
2.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-11-05 10:20:05 -04:00
class TagsController < ApplicationController
2019-07-20 18:53:28 -04:00
include SignatureVerification
PAGE_SIZE = 20
layout 'public'
2019-07-20 18:53:28 -04:00
before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_tag
2017-10-07 14:00:35 -04:00
before_action :set_body_classes
before_action :set_instance_presenter
2016-11-05 10:20:05 -04:00
def show
respond_to do |format|
2017-10-07 14:00:35 -04:00
format.html do
2017-11-21 01:13:37 -05:00
use_pack 'about'
2019-07-20 18:53:28 -04:00
expires_in 0, public: true
2019-03-12 12:34:00 -04:00
@initial_state_json = ActiveModelSerializers::SerializableResource.new(
InitialStatePresenter.new(settings: {}, token: current_session&.token),
serializer: InitialStateSerializer, monsterfork_api: monsterfork_api
2019-03-12 12:34:00 -04:00
).to_json
2017-10-07 14:00:35 -04:00
end
format.rss do
2019-07-20 18:53:28 -04:00
expires_in 0, public: true
@statuses = HashtagQueryService.new.call(@tag, params.slice(:any, :all, :none)).limit(PAGE_SIZE)
@statuses = cache_collection(@statuses, Status)
render xml: RSS::TagSerializer.render(@tag, @statuses)
end
format.json do
2019-07-20 18:53:28 -04:00
expires_in 3.minutes, public: public_fetch_mode?
2019-03-12 12:34:00 -04:00
@statuses = HashtagQueryService.new.call(@tag, params.slice(:any, :all, :none), current_account, params[:local]).paginate_by_max_id(PAGE_SIZE, params[:max_id])
2017-10-07 14:00:35 -04:00
@statuses = cache_collection(@statuses, Status)
2019-07-20 18:53:28 -04:00
render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
end
end
end
private
2019-07-20 18:53:28 -04:00
def set_tag
@tag = Tag.find_normalized!(params[:id])
end
2017-10-07 14:00:35 -04:00
def set_body_classes
@body_classes = 'with-modals'
2017-10-07 14:00:35 -04:00
end
def set_instance_presenter
@instance_presenter = InstancePresenter.new
end
def collection_presenter
ActivityPub::CollectionPresenter.new(
id: tag_url(@tag, params.slice(:any, :all, :none)),
type: :ordered,
size: @tag.statuses.count,
items: @statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s) }
)
2016-11-05 10:20:05 -04:00
end
end