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