mastodon/app/controllers/tags_controller.rb

66 lines
1.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-11-05 14:20:05 +00:00
class TagsController < ApplicationController
PAGE_SIZE = 20
layout 'public'
2017-10-07 18:00:35 +00:00
before_action :set_body_classes
before_action :set_instance_presenter
2016-11-05 14:20:05 +00:00
def show
2017-10-07 18:00:35 +00:00
@tag = Tag.find_by!(name: params[:id].downcase)
respond_to do |format|
2017-10-07 18:00:35 +00:00
format.html do
serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer)
@initial_state_json = serializable_resource.to_json
end
format.rss do
@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
@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 18:00:35 +00:00
@statuses = cache_collection(@statuses, Status)
render json: collection_presenter,
serializer: ActivityPub::CollectionSerializer,
adapter: ActivityPub::Adapter,
content_type: 'application/activity+json'
end
end
end
private
2017-10-07 18:00:35 +00:00
def set_body_classes
@body_classes = 'with-modals'
2017-10-07 18:00:35 +00: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 14:20:05 +00:00
end
2017-10-07 18:00:35 +00:00
def initial_state_params
{
settings: {},
token: current_session&.token,
}
end
2016-11-05 14:20:05 +00:00
end