]> cat aescling's git repositories - mastodon.git/commitdiff
Add option to disable emoji replacements
authorThibaut Girka <thib@sitedethib.com>
Mon, 12 Aug 2019 13:31:20 +0000 (15:31 +0200)
committerThibG <thib@sitedethib.com>
Mon, 12 Aug 2019 21:01:37 +0000 (23:01 +0200)
Fixes #647

The option is found in `/settings` (because that was easier to write it this
way) but only affects the glitch-soc front-end.

app/controllers/settings/preferences_controller.rb
app/javascript/flavours/glitch/util/emoji/index.js
app/javascript/flavours/glitch/util/initial_state.js
app/lib/user_settings_decorator.rb
app/models/user.rb
app/serializers/initial_state_serializer.rb
app/views/settings/preferences/appearance/show.html.haml
config/locales/simple_form.en.yml
config/settings.yml

index 418ea5d7ac65c2c9373db5b4f83949388dc179da..f05dbe0ea387e915e4bd5996d9e3fa6222275446 100644 (file)
@@ -49,6 +49,7 @@ class Settings::PreferencesController < Settings::BaseController
       :setting_expand_spoilers,
       :setting_reduce_motion,
       :setting_system_font_ui,
+      :setting_system_emoji_font,
       :setting_noindex,
       :setting_hide_network,
       :setting_hide_followers_count,
index 2f40f9b085876eb02531a268af6641cebfea7870..b2d13cc959a5ecb2b53004948698a2e247e9d915 100644 (file)
@@ -1,4 +1,4 @@
-import { autoPlayGif } from 'flavours/glitch/util/initial_state';
+import { autoPlayGif, useSystemEmojiFont } from 'flavours/glitch/util/initial_state';
 import unicodeMapping from './emoji_unicode_mapping_light';
 import Trie from 'substring-trie';
 
@@ -12,7 +12,7 @@ const emojify = (str, customEmojis = {}) => {
   let rtn = '', tagChars = tagCharsWithEmojis, invisible = 0;
   for (;;) {
     let match, i = 0, tag;
-    while (i < str.length && (tag = tagChars.indexOf(str[i])) === -1 && (invisible || !(match = trie.search(str.slice(i))))) {
+    while (i < str.length && (tag = tagChars.indexOf(str[i])) === -1 && (invisible || useSystemEmojiFont || !(match = trie.search(str.slice(i))))) {
       i += str.codePointAt(i) < 65536 ? 1 : 2;
     }
     let rend, replacement = '';
@@ -57,7 +57,7 @@ const emojify = (str, customEmojis = {}) => {
         }
       }
       i = rend;
-    } else { // matched to unicode emoji
+    } else if (!useSystemEmojiFont) { // matched to unicode emoji
       const { filename, shortCode } = unicodeMapping[match];
       const title = shortCode ? `:${shortCode}:` : '';
       replacement = `<img draggable="false" class="emojione" alt="${match}" title="${title}" src="${assetHost}/emoji/${filename}.svg" />`;
index caaa79bb35e067091468e4b711306d57ddcfe6ee..4b6227cac692813a837b84741a5b5e5b20552abb 100644 (file)
@@ -31,5 +31,6 @@ export const defaultContentType = getMeta('default_content_type');
 export const forceSingleColumn = getMeta('advanced_layout') === false;
 export const useBlurhash = getMeta('use_blurhash');
 export const usePendingItems = getMeta('use_pending_items');
+export const useSystemEmojiFont = getMeta('system_emoji_font');
 
 export default initialState;
index a52172707b7eb6743d1ab43e97692549e22bf1bb..c822d54de1d2c7c5c4afacb23dc1b879a5bfd9b0 100644 (file)
@@ -29,6 +29,7 @@ class UserSettingsDecorator
     user.settings['expand_spoilers']     = expand_spoilers_preference if change?('setting_expand_spoilers')
     user.settings['reduce_motion']       = reduce_motion_preference if change?('setting_reduce_motion')
     user.settings['system_font_ui']      = system_font_ui_preference if change?('setting_system_font_ui')
+    user.settings['system_emoji_font']   = system_emoji_font_preference if change?('setting_system_emoji_font')
     user.settings['noindex']             = noindex_preference if change?('setting_noindex')
     user.settings['hide_followers_count']= hide_followers_count_preference if change?('setting_hide_followers_count')
     user.settings['flavour']             = flavour_preference if change?('setting_flavour')
@@ -79,6 +80,10 @@ class UserSettingsDecorator
     boolean_cast_setting 'setting_system_font_ui'
   end
 
+  def system_emoji_font_preference
+    boolean_cast_setting 'setting_system_emoji_font'
+  end
+
   def auto_play_gif_preference
     boolean_cast_setting 'setting_auto_play_gif'
   end
index 45a4b89890b71e88976d4ad357528aa7ea7238b7..341227d3e2fa7075762d24bdbef5f73567805cf6 100644 (file)
@@ -108,7 +108,7 @@ class User < ApplicationRecord
            :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_media, :hide_network, :hide_followers_count,
            :expand_spoilers, :default_language, :aggregate_reblogs, :show_application,
            :advanced_layout, :use_blurhash, :use_pending_items, :trends,
-           :default_content_type,
+           :default_content_type, :system_emoji_font,
            to: :settings, prefix: :setting, allow_nil: false
 
   attr_reader :invite_code
index c8da6e725cd2e38b6cc315db23558c60591d125b..c8f6bec7a567cc3132a001d810cc4fe227208437 100644 (file)
@@ -53,6 +53,7 @@ class InitialStateSerializer < ActiveModel::Serializer
       store[:is_staff]          = object.current_account.user.staff?
       store[:trends]            = Setting.trends && object.current_account.user.setting_trends
       store[:default_content_type] = object.current_account.user.setting_default_content_type
+      store[:system_emoji_font] = object.current_account.user.setting_system_emoji_font
     end
 
     store
index 0bda49f44ac23c6b15a392418b6113c60ffa1791..900a7c6fb69ad8e14c295d8348c79d4efb9c1f01 100644 (file)
@@ -21,6 +21,7 @@
     = f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label, recommended: true
     = f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label
     = f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label
+    = f.input :setting_system_emoji_font, as: :boolean, wrapper: :with_label
 
   %h4= t 'appearance.discovery'
 
index 5da0cc45df36f307dab3d1c2029fafa03593180f..8f63df0131938935664802bbefc6fb4aa37f73be 100644 (file)
@@ -124,6 +124,7 @@ en:
         setting_reduce_motion: Reduce motion in animations
         setting_show_application: Disclose application used to send toots
         setting_skin: Skin
+        setting_system_emoji_font: Use system's default font for emojis (applies to Glitch flavour only)
         setting_system_font_ui: Use system's default font
         setting_theme: Site theme
         setting_trends: Show today's trends
index 10836db3f5f6aa77b22d554d3ead77ad5ae27774..70a9a3a4458808726afab7ee321b0c0cd8395f36 100644 (file)
@@ -29,6 +29,7 @@ defaults: &defaults
   reduce_motion: false
   show_application: false
   system_font_ui: false
+  system_emoji_font: false
   noindex: false
   hide_followers_count: false
   enable_keybase: true