Add option to disable emoji replacements

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.
This commit is contained in:
Thibaut Girka 2019-08-12 15:31:20 +02:00 committed by ThibG
parent cf421bafdf
commit 597ea5687a
9 changed files with 15 additions and 4 deletions

View 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,

View 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" />`;

View 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;

View 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

View 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

View 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

View 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'

View 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

View 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