2022-07-17 11:49:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::TagsController < Api::BaseController
|
|
|
|
before_action -> { doorkeeper_authorize! :follow, :write, :'write:follows' }, except: :show
|
|
|
|
before_action :require_user!, except: :show
|
|
|
|
before_action :set_or_create_tag
|
|
|
|
|
|
|
|
override_rate_limit_headers :follow, family: :follows
|
|
|
|
|
|
|
|
def show
|
2023-04-25 13:41:34 +00:00
|
|
|
cache_if_unauthenticated!
|
2022-07-17 11:49:29 +00:00
|
|
|
render json: @tag, serializer: REST::TagSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow
|
2022-11-21 09:35:09 +00:00
|
|
|
TagFollow.create_with(rate_limit: true).find_or_create_by!(tag: @tag, account: current_account)
|
2022-07-17 11:49:29 +00:00
|
|
|
render json: @tag, serializer: REST::TagSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def unfollow
|
|
|
|
TagFollow.find_by(account: current_account, tag: @tag)&.destroy!
|
2023-07-17 11:56:28 +00:00
|
|
|
TagUnmergeWorker.perform_async(@tag.id, current_account.id)
|
2022-07-17 11:49:29 +00:00
|
|
|
render json: @tag, serializer: REST::TagSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_or_create_tag
|
2022-11-10 04:49:30 +00:00
|
|
|
return not_found unless Tag::HASHTAG_NAME_RE.match?(params[:id])
|
2023-02-20 05:58:28 +00:00
|
|
|
|
2022-07-17 11:49:29 +00:00
|
|
|
@tag = Tag.find_normalized(params[:id]) || Tag.new(name: Tag.normalize(params[:id]), display_name: params[:id])
|
|
|
|
end
|
|
|
|
end
|