Add emoji alias-names support

This commit is contained in:
KMY 2023-05-22 10:44:32 +09:00
parent dd05f2b58c
commit 8638e715cb
9 changed files with 42 additions and 6 deletions

View file

@ -74,7 +74,7 @@ module Admin
end
def form_custom_emoji_batch_params
params.require(:form_custom_emoji_batch).permit(:action, :category_id, :category_name, custom_emoji_ids: [])
params.require(:form_custom_emoji_batch).permit(:action, :category_id, :category_name, :aliases_raw, custom_emoji_ids: [])
end
end
end

View file

@ -143,6 +143,8 @@ export const buildCustomEmojis = (customEmojis) => {
const shortcode = emoji.get('shortcode');
const url = autoPlayGif ? emoji.get('url') : emoji.get('static_url');
const name = shortcode.replace(':', '');
const aliases = emoji.get('aliases');
const keywords = aliases ? [name, ...aliases] : [name];
emojis.push({
id: name,
@ -150,7 +152,7 @@ export const buildCustomEmojis = (customEmojis) => {
short_names: [name],
text: '',
emoticons: [],
keywords: [name],
keywords,
imageUrl: url,
custom: true,
customCategory: emoji.get('category'),

View file

@ -21,6 +21,7 @@
# image_storage_schema_version :integer
# image_width :integer
# image_height :integer
# aliases :jsonb
#
class CustomEmoji < ApplicationRecord
@ -80,6 +81,17 @@ class CustomEmoji < ApplicationRecord
size(Rails.configuration.x.use_s3 ? image.url : image.path)
end
def aliases_raw
return '' if aliases.nil? || aliases.blank?
aliases.join(',')
end
def aliases_raw=(raw)
aliases = raw.split(',').filter(&:present?).uniq
self[:aliases] = aliases
end
class << self
def from_text(text, domain = nil)
return [] if text.blank?

View file

@ -6,7 +6,7 @@ class Form::CustomEmojiBatch
include AccountableConcern
attr_accessor :custom_emoji_ids, :action, :current_account,
:category_id, :category_name, :visible_in_picker
:category_id, :category_name, :aliases_raw, :visible_in_picker
def save
case action
@ -43,7 +43,8 @@ class Form::CustomEmojiBatch
end
custom_emojis.each do |custom_emoji|
custom_emoji.update(category_id: category&.id)
new_aliases_raw = (aliases_raw.presence || custom_emoji.aliases_raw)
custom_emoji.update(category_id: category&.id, aliases_raw: new_aliases_raw)
log_action :update, custom_emoji
end
end

View file

@ -8,6 +8,7 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer
attribute :category, if: :category_loaded?
attribute :width, if: :width?
attribute :height, if: :height?
attribute :aliases, if: :aliases?
def url
full_asset_url(object.image.url)
@ -40,4 +41,8 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer
def height
object.respond_to?(:image_height) ? object.image_height : object.height
end
def aliases?
object.respond_to?(:aliases) && object.aliases.present?
end
end

View file

@ -10,6 +10,8 @@
- if custom_emoji.local?
%span.account-role.bot= custom_emoji.category&.name || t('admin.custom_emojis.uncategorized')
%br/
%span= custom_emoji.aliases_raw
.batch-table__row__content__extra
- if custom_emoji.local?

View file

@ -78,6 +78,12 @@
.label_input
= f.text_field :category_name, class: 'string optional', placeholder: t('admin.custom_emojis.create_new_category'), 'aria-label': t('admin.custom_emojis.create_new_category')
.fields-row
.fields-group.fields-row__column
.input.string.optional
.label_input
= f.text_field :aliases_raw, class: 'string optional', placeholder: 'Alias names', 'aria-label': 'Alias names'
.batch-table__body
- if @custom_emojis.empty?
= nothing_here 'nothing-here--under-tabs'

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddAliasesToCustomEmoji < ActiveRecord::Migration[6.1]
def change
add_column :custom_emojis, :aliases, :jsonb
end
end

View file

@ -12,7 +12,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_05_14_030455) do
ActiveRecord::Schema.define(version: 2023_05_21_122642) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -438,6 +438,7 @@ ActiveRecord::Schema.define(version: 2023_05_14_030455) do
t.integer "image_storage_schema_version"
t.integer "image_width"
t.integer "image_height"
t.jsonb "aliases"
t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
end
@ -1487,4 +1488,4 @@ ActiveRecord::Schema.define(version: 2023_05_14_030455) do
end
# rubocop:enable all
#rubocop:enable all