Add reactiondeck limit variable and improve sql

This commit is contained in:
KMY 2023-05-27 10:13:18 +09:00
parent 8e794d50b5
commit f93679566b
4 changed files with 13 additions and 4 deletions

View file

@ -20,9 +20,16 @@ class Api::V1::ReactionDeckController < Api::BaseController
def create
deck = []
shortcodes = []
(deck_params['emojis'] || []).each do |shortcode|
shortcode = shortcode.delete(':')
custom_emoji = CustomEmoji.find_by(shortcode: shortcode, domain: nil)
shortcodes << shortcode.delete(':')
break if shortcodes.length >= User::REACTION_DECK_MAX
end
custom_emojis = CustomEmoji.where(shortcode: shortcodes, domain: nil)
shortcodes.each do |shortcode|
custom_emoji = custom_emojis.find { |em| em.shortcode == shortcode }
emoji_data = {}

View file

@ -65,6 +65,8 @@ class User < ApplicationRecord
# to check their feed
ACTIVE_DURATION = ENV.fetch('USER_ACTIVE_DAYS', 7).to_i.days.freeze
REACTION_DECK_MAX = 256
devise :two_factor_authenticatable,
otp_secret_encryption_key: Rails.configuration.x.otp_secret

View file

@ -86,7 +86,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
},
reaction_deck: {
max_emojis: 32_767,
max_emojis: User::REACTION_DECK_MAX,
},
reactions: {

View file

@ -92,7 +92,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
},
reaction_deck: {
max_emojis: 32_767,
max_emojis: User::REACTION_DECK_MAX,
},
reactions: {