2016-11-15 16:56:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-05 15:20:05 +01:00
|
|
|
class TagsController < ApplicationController
|
2018-04-25 02:10:02 +02:00
|
|
|
PAGE_SIZE = 20
|
|
|
|
|
2019-01-16 19:47:46 +01:00
|
|
|
layout 'public'
|
|
|
|
|
2017-10-07 20:00:35 +02:00
|
|
|
before_action :set_body_classes
|
|
|
|
before_action :set_instance_presenter
|
2016-11-05 17:44:14 +01:00
|
|
|
|
2016-11-05 15:20:05 +01:00
|
|
|
def show
|
2019-03-13 13:02:13 +01:00
|
|
|
@tag = Tag.find_normalized!(params[:id])
|
2017-07-15 03:01:39 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
2017-10-07 20:00:35 +02:00
|
|
|
format.html do
|
2019-03-12 17:34:00 +01:00
|
|
|
@initial_state_json = ActiveModelSerializers::SerializableResource.new(
|
|
|
|
InitialStatePresenter.new(settings: {}, token: current_session&.token),
|
|
|
|
serializer: InitialStateSerializer
|
|
|
|
).to_json
|
2017-10-07 20:00:35 +02:00
|
|
|
end
|
2017-07-15 03:01:39 +02:00
|
|
|
|
2018-04-25 02:10:02 +02:00
|
|
|
format.rss do
|
2018-11-05 18:53:25 +01:00
|
|
|
@statuses = HashtagQueryService.new.call(@tag, params.slice(:any, :all, :none)).limit(PAGE_SIZE)
|
2018-04-25 02:10:02 +02:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
|
|
|
|
|
|
|
render xml: RSS::TagSerializer.render(@tag, @statuses)
|
|
|
|
end
|
|
|
|
|
2017-07-15 03:01:39 +02:00
|
|
|
format.json do
|
2019-03-12 17:34:00 +01: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 20:00:35 +02:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
|
|
|
|
2017-10-07 17:43:42 +02:00
|
|
|
render json: collection_presenter,
|
|
|
|
serializer: ActivityPub::CollectionSerializer,
|
|
|
|
adapter: ActivityPub::Adapter,
|
|
|
|
content_type: 'application/activity+json'
|
2017-07-15 03:01:39 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-10-07 20:00:35 +02:00
|
|
|
def set_body_classes
|
2018-07-31 01:14:33 +02:00
|
|
|
@body_classes = 'with-modals'
|
2017-10-07 20:00:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_instance_presenter
|
|
|
|
@instance_presenter = InstancePresenter.new
|
|
|
|
end
|
|
|
|
|
2017-07-15 03:01:39 +02:00
|
|
|
def collection_presenter
|
|
|
|
ActivityPub::CollectionPresenter.new(
|
2018-11-05 18:53:25 +01:00
|
|
|
id: tag_url(@tag, params.slice(:any, :all, :none)),
|
2017-07-15 03:01:39 +02:00
|
|
|
type: :ordered,
|
|
|
|
size: @tag.statuses.count,
|
|
|
|
items: @statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s) }
|
|
|
|
)
|
2016-11-05 15:20:05 +01:00
|
|
|
end
|
|
|
|
end
|