Feature: Unlisted custom emojis (#5485)

This commit is contained in:
nullkal 2017-10-27 23:11:30 +09:00 committed by Eugen Rochko
parent 0cb329f63a
commit 781105293c
9 changed files with 32 additions and 6 deletions

View file

@ -22,6 +22,14 @@ module Admin
end end
end end
def update
if @custom_emoji.update(resource_params)
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.updated_msg')
else
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.update_failed_msg')
end
end
def destroy def destroy
@custom_emoji.destroy @custom_emoji.destroy
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg') redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg')
@ -56,7 +64,7 @@ module Admin
end end
def resource_params def resource_params
params.require(:custom_emoji).permit(:shortcode, :image) params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
end end
def filtered_custom_emojis def filtered_custom_emojis

View file

@ -46,7 +46,7 @@ const getFrequentlyUsedEmojis = createSelector([
const getCustomEmojis = createSelector([ const getCustomEmojis = createSelector([
state => state.get('custom_emojis'), state => state.get('custom_emojis'),
], emojis => emojis.sort((a, b) => { ], emojis => emojis.filter(e => e.get('visible_in_picker')).sort((a, b) => {
const aShort = a.get('shortcode').toLowerCase(); const aShort = a.get('shortcode').toLowerCase();
const bShort = b.get('shortcode').toLowerCase(); const bShort = b.get('shortcode').toLowerCase();

View file

@ -15,6 +15,7 @@
# disabled :boolean default(FALSE), not null # disabled :boolean default(FALSE), not null
# uri :string # uri :string
# image_remote_url :string # image_remote_url :string
# visible_in_picker :boolean default(TRUE), not null
# #
class CustomEmoji < ApplicationRecord class CustomEmoji < ApplicationRecord

View file

@ -3,7 +3,7 @@
class REST::CustomEmojiSerializer < ActiveModel::Serializer class REST::CustomEmojiSerializer < ActiveModel::Serializer
include RoutingHelper include RoutingHelper
attributes :shortcode, :url, :static_url attributes :shortcode, :url, :static_url, :visible_in_picker
def url def url
full_asset_url(object.image.url) full_asset_url(object.image.url)

View file

@ -9,7 +9,12 @@
- else - else
= custom_emoji.domain = custom_emoji.domain
%td %td
- unless custom_emoji.local? - if custom_emoji.local?
- if custom_emoji.visible_in_picker
= table_link_to 'eye', t('admin.custom_emojis.listed'), admin_custom_emoji_path(custom_emoji, custom_emoji: { visible_in_picker: false }), method: :patch
- else
= table_link_to 'eye-slash', t('admin.custom_emojis.unlisted'), admin_custom_emoji_path(custom_emoji, custom_emoji: { visible_in_picker: true }), method: :patch
- else
= table_link_to 'copy', t('admin.custom_emojis.copy'), copy_admin_custom_emoji_path(custom_emoji, page: params[:page]), method: :post = table_link_to 'copy', t('admin.custom_emojis.copy'), copy_admin_custom_emoji_path(custom_emoji, page: params[:page]), method: :post
%td %td
- if custom_emoji.disabled? - if custom_emoji.disabled?

View file

@ -130,11 +130,15 @@ en:
enable: Enable enable: Enable
enabled_msg: Successfully enabled that emoji enabled_msg: Successfully enabled that emoji
image_hint: PNG up to 50KB image_hint: PNG up to 50KB
listed: Listed
new: new:
title: Add new custom emoji title: Add new custom emoji
shortcode: Shortcode shortcode: Shortcode
shortcode_hint: At least 2 characters, only alphanumeric characters and underscores shortcode_hint: At least 2 characters, only alphanumeric characters and underscores
title: Custom emojis title: Custom emojis
unlisted: Unlisted
update_failed_msg: Could not update that emoji
updated_msg: Emoji successfully updated!
upload: Upload upload: Upload
domain_blocks: domain_blocks:
add_new: Add new add_new: Add new

View file

@ -140,7 +140,7 @@ Rails.application.routes.draw do
resource :two_factor_authentication, only: [:destroy] resource :two_factor_authentication, only: [:destroy]
end end
resources :custom_emojis, only: [:index, :new, :create, :destroy] do resources :custom_emojis, only: [:index, :new, :create, :update, :destroy] do
member do member do
post :copy post :copy
post :enable post :enable

View file

@ -0,0 +1,7 @@
class AddVisibleInPickerToCustomEmoji < ActiveRecord::Migration[5.1]
def change
safety_assured {
add_column :custom_emojis, :visible_in_picker, :boolean, default: true, null: false
}
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171010025614) do ActiveRecord::Schema.define(version: 20171020084748) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -111,6 +111,7 @@ ActiveRecord::Schema.define(version: 20171010025614) do
t.boolean "disabled", default: false, null: false t.boolean "disabled", default: false, null: false
t.string "uri" t.string "uri"
t.string "image_remote_url" t.string "image_remote_url"
t.boolean "visible_in_picker", default: true, null: false
t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
end end