diff --git a/app/controllers/admin/custom_emojis_controller.rb b/app/controllers/admin/custom_emojis_controller.rb index 00d069cdfb..37032e6ba4 100644 --- a/app/controllers/admin/custom_emojis_controller.rb +++ b/app/controllers/admin/custom_emojis_controller.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'fastimage' + module Admin class CustomEmojisController < BaseController def index @@ -18,7 +20,11 @@ module Admin def create authorize :custom_emoji, :create? + image_size = FastImage.size(params[:custom_emoji][:image]) + @custom_emoji = CustomEmoji.new(resource_params) + @custom_emoji.image_width = image_size[0] + @custom_emoji.image_height = image_size[1] if @custom_emoji.save log_action :create, @custom_emoji diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index 0ebb28dc23..7e9eb91ca5 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -19,6 +19,8 @@ # visible_in_picker :boolean default(TRUE), not null # category_id :bigint(8) # image_storage_schema_version :integer +# image_width :integer +# image_height :integer # class CustomEmoji < ApplicationRecord diff --git a/app/serializers/rest/custom_emoji_serializer.rb b/app/serializers/rest/custom_emoji_serializer.rb index aff58e4d94..a4d2556849 100644 --- a/app/serializers/rest/custom_emoji_serializer.rb +++ b/app/serializers/rest/custom_emoji_serializer.rb @@ -3,7 +3,7 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer include RoutingHelper - attributes :shortcode, :url, :static_url, :visible_in_picker + attributes :shortcode, :url, :static_url, :visible_in_picker, :width, :height attribute :category, if: :category_loaded? @@ -22,4 +22,12 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer def category_loaded? object.association(:category).loaded? && object.category.present? end + + def width + object.image_width + end + + def height + object.image_height + end end diff --git a/app/serializers/rest/emoji_reactions_grouped_by_name_serializer.rb b/app/serializers/rest/emoji_reactions_grouped_by_name_serializer.rb index d4230de61a..48c70a4808 100644 --- a/app/serializers/rest/emoji_reactions_grouped_by_name_serializer.rb +++ b/app/serializers/rest/emoji_reactions_grouped_by_name_serializer.rb @@ -9,6 +9,8 @@ class REST::EmojiReactionsGroupedByNameSerializer < ActiveModel::Serializer attribute :url, if: :custom_emoji? attribute :static_url, if: :custom_emoji? attribute :domain, if: :custom_emoji? + attribute :width, if: :custom_emoji? + attribute :height, if: :custom_emoji? attribute :account_ids, if: :account_ids? def current_user? @@ -34,4 +36,12 @@ class REST::EmojiReactionsGroupedByNameSerializer < ActiveModel::Serializer def domain object.custom_emoji.domain end + + def width + object.custom_emoji.image_width + end + + def height + object.custom_emoji.image_height + end end diff --git a/db/migrate/20230308061833_add_image_size_to_custom_emojis.rb b/db/migrate/20230308061833_add_image_size_to_custom_emojis.rb new file mode 100644 index 0000000000..ff048c6903 --- /dev/null +++ b/db/migrate/20230308061833_add_image_size_to_custom_emojis.rb @@ -0,0 +1,6 @@ +class AddImageSizeToCustomEmojis < ActiveRecord::Migration[6.1] + def change + add_column :custom_emojis, :image_width, :integer + add_column :custom_emojis, :image_height, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index cd085429f2..93a923bbe2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_02_23_102416) do +ActiveRecord::Schema.define(version: 2023_03_08_061833) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -338,6 +338,8 @@ ActiveRecord::Schema.define(version: 2023_02_23_102416) do t.boolean "visible_in_picker", default: true, null: false t.bigint "category_id" t.integer "image_storage_schema_version" + t.integer "image_width" + t.integer "image_height" t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true end