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
|
|
|
|
|
2020-06-08 18:18:47 -04:00
|
|
|
PAGE_SIZE = 20
|
|
|
|
PAGE_SIZE_MAX = 200
|
2018-04-24 20:10:02 -04:00
|
|
|
|
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-30 05:10:46 -04:00
|
|
|
before_action :authenticate_user!, if: :whitelist_mode?
|
2020-04-18 15:52:39 -04:00
|
|
|
before_action :set_local
|
2020-09-07 05:02:04 -04:00
|
|
|
before_action :set_tag
|
|
|
|
before_action :set_statuses
|
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
|
|
|
|
2020-06-19 13:18:47 -04:00
|
|
|
skip_before_action :require_functional!, unless: :whitelist_mode?
|
2019-09-27 19:33:27 -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
|
2017-11-21 01:13:37 -05:00
|
|
|
use_pack 'about'
|
2019-07-08 06:03:45 -04:00
|
|
|
expires_in 0, public: true
|
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-04-24 20:10:02 -04:00
|
|
|
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
|
|
|
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
|
2019-08-07 04:01:55 -04:00
|
|
|
@tag = Tag.usable.find_normalized!(params[:id])
|
2019-07-08 06:03:45 -04:00
|
|
|
end
|
|
|
|
|
2020-04-18 15:52:39 -04:00
|
|
|
def set_local
|
|
|
|
@local = truthy_param?(:local)
|
|
|
|
end
|
|
|
|
|
2020-09-07 05:02:04 -04:00
|
|
|
def set_statuses
|
|
|
|
case request.format&.to_sym
|
|
|
|
when :json
|
|
|
|
@statuses = cache_collection(TagFeed.new(@tag, current_account, local: @local).get(PAGE_SIZE, params[:max_id], params[:since_id], params[:min_id]), Status)
|
|
|
|
when :rss
|
|
|
|
@statuses = cache_collection(TagFeed.new(@tag, nil, local: @local).get(limit_param), Status)
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2020-09-07 05:02:04 -04:00
|
|
|
def limit_param
|
|
|
|
params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
|
|
|
|
end
|
|
|
|
|
2017-07-14 21:01:39 -04:00
|
|
|
def collection_presenter
|
|
|
|
ActivityPub::CollectionPresenter.new(
|
2020-09-07 05:02:04 -04:00
|
|
|
id: tag_url(@tag),
|
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
|