diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-07-21 01:44:16 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-08-30 05:44:01 -0500 |
commit | 263ead73616dba43a0337c2a3edaf96a6382d533 (patch) | |
tree | ca47a9366dbbdf95018c55bde32b59d6b05c8299 /app/controllers | |
parent | 21de9efc2d89ce8dbb9edb997f8a3b99f831d05a (diff) |
[Feature] Add post and thread (un)hiding to backend
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/api/v1/statuses/hides_controller.rb | 28 | ||||
-rw-r--r-- | app/controllers/api/v1/statuses/mutes_controller.rb | 4 |
2 files changed, 31 insertions, 1 deletions
diff --git a/app/controllers/api/v1/statuses/hides_controller.rb b/app/controllers/api/v1/statuses/hides_controller.rb new file mode 100644 index 000000000..8c5457c82 --- /dev/null +++ b/app/controllers/api/v1/statuses/hides_controller.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class Api::V1::Statuses::HidesController < Api::BaseController + include Authorization + + before_action -> { doorkeeper_authorize! :write, :'write:mutes' } + before_action :require_user! + before_action :set_status + + def create + MuteStatusService.new.call(current_account, @status) + render json: @status, serializer: REST::StatusSerializer + end + + def destroy + current_account.unmute_status!(@status) + render json: @status, serializer: REST::StatusSerializer + end + + private + + def set_status + @status = Status.find(params[:status_id]) + authorize @status, :show? + rescue Mastodon::NotPermittedError + not_found + end +end diff --git a/app/controllers/api/v1/statuses/mutes_controller.rb b/app/controllers/api/v1/statuses/mutes_controller.rb index 87071a2b9..73d9df734 100644 --- a/app/controllers/api/v1/statuses/mutes_controller.rb +++ b/app/controllers/api/v1/statuses/mutes_controller.rb @@ -9,12 +9,14 @@ class Api::V1::Statuses::MutesController < Api::BaseController before_action :set_conversation def create - current_account.mute_conversation!(@conversation) + MuteConversationService.new.call(current_account, @status.conversation, hidden: truthy_param?(:hide)) @mutes_map = { @conversation.id => true } render json: @status, serializer: REST::StatusSerializer end + alias update create + def destroy current_account.unmute_conversation!(@conversation) @mutes_map = { @conversation.id => false } |