nas/app/controllers/api/v1/statuses/emoji_reactions_controller.rb
KMY(雪あすか) 44b739a39a
Add: Webでの引用表示 (#50)
* Add compacted component

* 引用表示の間にコンテナをはさみ、不要なコードを削除

* 引用APIを作成、ついでにブロック状況を引用APIに反映

* テスト修正など

* 引用をキャッシュに登録

* `quote_id`が`quote_of_id`になったのをSerializerに反映

* Fix test

* 引用をフィルターの対象に含める設定+エラー修正

* ストリーミングの存在しないプロパティ削除によるエラーを修正

* Fix lint

* 他のサーバーから来た引用付き投稿を処理

* Fix test

* フィルター設定時エラーの調整

* 画像つき投稿のスタイルを調整

* 画像つき投稿の最大高さを調整

* 引用禁止・非表示の設定を追加

* ブロック対応

* マイグレーションコード調整

* 引用設定の翻訳を作成

* Lint修正

* 参照1つの場合は引用に変換する設定を削除

* 不要になったテストを削除

* ブロック設定追加、バグ修正

* 他サーバーへ引用送信・受け入れ
2023-10-02 11:12:51 +09:00

61 lines
2 KiB
Ruby

# frozen_string_literal: true
class Api::V1::Statuses::EmojiReactionsController < Api::BaseController
include Authorization
before_action -> { doorkeeper_authorize! :write, :'write:emoji_reactions' }
before_action :require_user!
before_action :set_status, only: %i(create update destroy)
before_action :set_status_without_authorize, only: [:destroy]
def create
create_private(params[:emoji] || params[:id])
end
# For compatible with Fedibird API
def update
create_private(params[:id])
end
def destroy
emoji = params[:emoji] || params[:id]
if emoji
shortcode, domain = emoji.split('@')
emoji_reaction = EmojiReaction.where(account_id: current_account.id).where(status_id: @status.id).where(name: shortcode)
.find { |reaction| domain == '' ? reaction.custom_emoji.nil? : reaction.custom_emoji&.domain == domain }
authorize @status, :show? if emoji_reaction.nil?
UnEmojiReactService.new.call(current_account.id, @status.id, emoji_reaction) if emoji_reaction.present?
end
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(
[@status], current_account.id
)
rescue Mastodon::NotPermittedError
not_found
end
private
def create_private(emoji)
count = EmojiReaction.where(account: current_account, status: @status).count
raise Mastodon::ValidationError, I18n.t('reactions.errors.limit_reached') if count >= EmojiReaction::EMOJI_REACTION_PER_ACCOUNT_LIMIT
raise Mastodon::ValidationError, I18n.t('reactions.errors.disabled') unless Setting.enable_emoji_reaction
EmojiReactService.new.call(current_account, @status, emoji)
render json: @status, serializer: REST::StatusSerializer
end
def set_status
set_status_without_authorize
authorize @status, :show?
rescue Mastodon::NotPermittedError
not_found
end
def set_status_without_authorize
@status = Status.find(params[:status_id])
end
end