2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-05 10:20:05 -04:00
|
|
|
class TagsController < ApplicationController
|
2019-07-11 14:11:09 -04:00
|
|
|
include SignatureVerification
|
|
|
|
|
2018-04-24 20:10:02 -04:00
|
|
|
PAGE_SIZE = 20
|
|
|
|
|
2019-01-16 13:47:46 -05:00
|
|
|
layout 'public'
|
|
|
|
|
2019-07-11 14:11:09 -04:00
|
|
|
before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
|
2019-07-08 06:03:45 -04:00
|
|
|
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 12:44:14 -04:00
|
|
|
|
2016-11-05 10:20:05 -04:00
|
|
|
def show
|
2017-07-14 21:01:39 -04:00
|
|
|
respond_to do |format|
|
2017-10-07 14:00:35 -04:00
|
|
|
format.html do
|
2019-07-08 06:03:45 -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
|
|
|
|
).to_json
|
2017-10-07 14:00:35 -04:00
|
|
|
end
|
2017-07-14 21:01:39 -04:00
|
|
|
|
2018-04-24 20:10:02 -04:00
|
|
|
format.rss do
|
2019-07-08 06:03:45 -04:00
|
|
|
expires_in 0, public: true
|
|
|
|
|
2018-11-05 12:53:25 -05:00
|
|
|
@statuses = HashtagQueryService.new.call(@tag, params.slice(:any, :all, :none)).limit(PAGE_SIZE)
|
2018-04-24 20:10:02 -04:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
|
|
|
|
|
|
|
render xml: RSS::TagSerializer.render(@tag, @statuses)
|
|
|
|
end
|
|
|
|
|
2017-07-14 21:01:39 -04:00
|
|
|
format.json do
|
2019-07-11 14:11:09 -04:00
|
|
|
expires_in 3.minutes, public: public_fetch_mode?
|
2019-07-08 06:03:45 -04:00
|
|
|
|
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-08 06:03:45 -04:00
|
|
|
render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
|
2017-07-14 21:01:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-07-08 06:03:45 -04:00
|
|
|
def set_tag
|
|
|
|
@tag = Tag.find_normalized!(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-10-07 14:00:35 -04:00
|
|
|
def set_body_classes
|
2018-07-30 19:14:33 -04:00
|
|
|
@body_classes = 'with-modals'
|
2017-10-07 14:00:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_instance_presenter
|
|
|
|
@instance_presenter = InstancePresenter.new
|
|
|
|
end
|
|
|
|
|
2017-07-14 21:01:39 -04:00
|
|
|
def collection_presenter
|
|
|
|
ActivityPub::CollectionPresenter.new(
|
2018-11-05 12:53:25 -05:00
|
|
|
id: tag_url(@tag, params.slice(:any, :all, :none)),
|
2017-07-14 21:01:39 -04:00
|
|
|
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
|