diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-07-17 13:49:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-17 13:49:29 +0200 |
commit | c3f0621a59a74d0e20e6db6170894871c48e8f0f (patch) | |
tree | df58568b5fbb86042f9dad4ba772f47d305e6086 /app/controllers/api/v1/tags_controller.rb | |
parent | ecb3bb3256fe1bab0d7a63829cdce914b2b509a9 (diff) |
Add ability to follow hashtags (#18809)
Diffstat (limited to 'app/controllers/api/v1/tags_controller.rb')
-rw-r--r-- | app/controllers/api/v1/tags_controller.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/controllers/api/v1/tags_controller.rb b/app/controllers/api/v1/tags_controller.rb new file mode 100644 index 000000000..d45015ff5 --- /dev/null +++ b/app/controllers/api/v1/tags_controller.rb @@ -0,0 +1,29 @@ +# 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 + render json: @tag, serializer: REST::TagSerializer + end + + def follow + TagFollow.create!(tag: @tag, account: current_account, rate_limit: true) + render json: @tag, serializer: REST::TagSerializer + end + + def unfollow + TagFollow.find_by(account: current_account, tag: @tag)&.destroy! + render json: @tag, serializer: REST::TagSerializer + end + + private + + def set_or_create_tag + @tag = Tag.find_normalized(params[:id]) || Tag.new(name: Tag.normalize(params[:id]), display_name: params[:id]) + end +end |