Move emoji reaction limitation constraints

This commit is contained in:
KMY 2023-03-08 16:31:22 +09:00 committed by YoheiZuho
parent 1f82788629
commit 3f5142c2f8
6 changed files with 15 additions and 5 deletions

View File

@ -3,7 +3,6 @@
class Api::BaseController < ApplicationController
DEFAULT_STATUSES_LIMIT = 20
DEFAULT_ACCOUNTS_LIMIT = 40
DEFAULT_EMOJI_REACTION_LIMIT = 10
include Api::RateLimitHeaders
include Api::AccessTokenTrackingConcern

View File

@ -42,7 +42,7 @@ class Api::V1::Statuses::EmojiReactionsController < Api::BaseController
def create_private(emoji)
count = EmojiReaction.where(account: current_account, status: @status).count
if count >= DEFAULT_EMOJI_REACTION_LIMIT
if count >= EmojiReaction::EMOJI_REACTION_PER_ACCOUNT_LIMIT
bad_request
return
end

View File

@ -40,9 +40,7 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
end
end
return if @account.reacted?(@original_status, shortcode, emoji)
return if EmojiReaction.where(account: @account, status: @original_status).count >= BaseController::DEFAULT_EMOJI_REACTION_LIMIT
return if EmojiReaction.where(account: @account, status: @original_status).count >= EmojiReaction::EMOJI_REACTION_PER_ACCOUNT_LIMIT
EmojiReaction.find_by(account: @account, status: @original_status)&.destroy
reaction = @original_status.emoji_reactions.create!(account: @account, name: shortcode, custom_emoji: emoji, uri: @json['id'])

View File

@ -17,6 +17,9 @@
class EmojiReaction < ApplicationRecord
include Paginable
EMOJI_REACTION_LIMIT = 32767
EMOJI_REACTION_PER_ACCOUNT_LIMIT = 5
update_index('statuses', :status)
belongs_to :account, inverse_of: :emoji_reactions

View File

@ -81,6 +81,11 @@ class REST::InstanceSerializer < ActiveModel::Serializer
translation: {
enabled: TranslationService.configured?,
},
emoji_reactions: {
max_reactions: EmojiReaction::EMOJI_REACTION_LIMIT,
max_reactions_per_account: EmojiReaction::EMOJI_REACTION_PER_ACCOUNT_LIMIT,
},
}
end

View File

@ -83,6 +83,11 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
min_expiration: PollValidator::MIN_EXPIRATION,
max_expiration: PollValidator::MAX_EXPIRATION,
},
emoji_reactions: {
max_reactions: EmojiReaction::EMOJI_REACTION_LIMIT,
max_reactions_per_account: EmojiReaction::EMOJI_REACTION_PER_ACCOUNT_LIMIT,
},
}
end