diff --git a/frontend_tests/node_tests/emoji.js b/frontend_tests/node_tests/emoji.js index 9da5c20818..5a6e8b7bf2 100644 --- a/frontend_tests/node_tests/emoji.js +++ b/frontend_tests/node_tests/emoji.js @@ -50,6 +50,7 @@ run_test('get_canonical_name', () => { var canonical_name = emoji.get_canonical_name('realm_emoji'); assert.equal(canonical_name, 'realm_emoji'); + var orig_emoji_codes = global.emoji_codes; global.emoji_codes = { name_to_codepoint: { '+1': '1f44d', @@ -71,6 +72,7 @@ run_test('get_canonical_name', () => { emoji.get_canonical_name('non_existent'); assert.equal(blueslip.get_test_logs('error').length, 1); blueslip.clear_test_data(); + global.emoji_codes = orig_emoji_codes; }); run_test('translate_emoticons_to_names', () => { @@ -95,9 +97,9 @@ run_test('translate_emoticons_to_names', () => { {name: 'between symbols', original: 'Hello.! World.', expected: 'Hello.! World.'}, {name: 'before end of sentence', original: 'Hello !', expected: 'Hello !'}, ]; - _.each(emoji.EMOTICON_CONVERSIONS, (full_name, shortcut) => { + _.each(emoji_codes.emoticon_conversions, (full_name, shortcut) => { _.each(testcases, (t) => { - var converted_value = ':' + full_name + ':'; + var converted_value = full_name; var original = t.original; var expected = t.expected; original = original.replace(/()/g, shortcut); diff --git a/static/js/emoji.js b/static/js/emoji.js index e1d2d2014c..606b64748c 100644 --- a/static/js/emoji.js +++ b/static/js/emoji.js @@ -18,18 +18,6 @@ var zulip_emoji = { deactivated: false, }; -// Emoticons, and which emoji they should become (without colons). Duplicate -// emoji are allowed. Changes here should be mimicked in `zerver/lib/emoji.py` -// and `templates/zerver/help/enable-emoticon-translations.md`. -exports.EMOTICON_CONVERSIONS = { - ':)': 'smiley', - '(:': 'smiley', - ':(': 'slight_frown', - '<3': 'heart', - ':|': 'expressionless', - ':/': 'confused', -}; - exports.update_emojis = function update_emojis(realm_emojis) { // exports.all_realm_emojis is emptied before adding the realm-specific emoji // to it. This makes sure that in case of deletion, the deleted realm_emojis @@ -148,9 +136,9 @@ exports.translate_emoticons_to_names = function translate_emoticons_to_names(tex return match; }; - for (var emoticon in exports.EMOTICON_CONVERSIONS) { - if (exports.EMOTICON_CONVERSIONS.hasOwnProperty(emoticon)) { - replacement_text = ':' + exports.EMOTICON_CONVERSIONS[emoticon] + ':'; + for (var emoticon in emoji_codes.emoticon_conversions) { + if (emoji_codes.emoticon_conversions.hasOwnProperty(emoticon)) { + replacement_text = emoji_codes.emoticon_conversions[emoticon]; var emoticon_regex = new RegExp('(' + util.escape_regexp(emoticon) + ')', 'g'); translated = translated.replace(emoticon_regex, emoticon_replacer); } diff --git a/tools/setup/emoji/build_emoji b/tools/setup/emoji/build_emoji index fb68e49758..7a05b26ed6 100755 --- a/tools/setup/emoji/build_emoji +++ b/tools/setup/emoji/build_emoji @@ -10,7 +10,7 @@ from typing import Any, Dict, List from emoji_setup_utils import generate_emoji_catalog, generate_codepoint_to_name_map, \ get_emoji_code, generate_name_to_codepoint_map, get_remapped_emojis_map, \ - emoji_names_for_picker, EMOJISETS + emoji_names_for_picker, EMOJISETS, EMOTICON_CONVERSIONS from emoji_names import EMOJI_NAME_MAPS ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../') @@ -35,6 +35,8 @@ exports.codepoint_to_name = %(codepoint_to_name)s; exports.emoji_catalog = %(emoji_catalog)s; +exports.emoticon_conversions = %(emoticon_conversions)s; + return exports; }()); if (typeof module !== 'undefined') { @@ -200,6 +202,7 @@ def generate_map_files(cache_path: str, emoji_catalog: Dict[str, List[str]]) -> 'name_to_codepoint': name_to_codepoint, 'codepoint_to_name': codepoint_to_name, 'emoji_catalog': emoji_catalog, + 'emoticon_conversions': EMOTICON_CONVERSIONS, }) NAME_TO_CODEPOINT_PATH = os.path.join(cache_path, 'name_to_codepoint.json') @@ -210,6 +213,10 @@ def generate_map_files(cache_path: str, emoji_catalog: Dict[str, List[str]]) -> with open(CODEPOINT_TO_NAME_PATH, 'w') as codepoint_to_name_file: codepoint_to_name_file.write(ujson.dumps(codepoint_to_name)) + EMOTICON_CONVERSIONS_PATH = os.path.join(cache_path, 'emoticon_conversions.json') + with open(EMOTICON_CONVERSIONS_PATH, 'w') as emoticon_conversions_file: + emoticon_conversions_file.write(ujson.dumps(EMOTICON_CONVERSIONS)) + def dump_emojis(cache_path: str) -> None: with open('emoji_map.json') as emoji_map_file: emoji_map = ujson.load(emoji_map_file) diff --git a/tools/setup/emoji/emoji_setup_utils.py b/tools/setup/emoji/emoji_setup_utils.py index 7bdfed826f..64344c6913 100644 --- a/tools/setup/emoji/emoji_setup_utils.py +++ b/tools/setup/emoji/emoji_setup_utils.py @@ -35,6 +35,17 @@ remapped_emojis = { "1f1fa": "1f1fa-1f1f8", # us } +# Emoticons and which emoji they should become. Duplicate emoji are allowed. +# Changes here should be mimicked in `templates/zerver/help/enable-emoticon-translations.md`. +EMOTICON_CONVERSIONS = { + ':)': ':smiley:', + '(:': ':smiley:', + ':(': ':slight_frown:', + '<3': ':heart:', + ':|': ':expressionless:', + ':/': ':confused:', +} + def emoji_names_for_picker(emoji_name_maps: Dict[str, Dict[str, Any]]) -> List[str]: emoji_names = [] # type: List[str] for emoji_code, name_info in emoji_name_maps.items(): diff --git a/version.py b/version.py index 942db1af21..de7d58f6f6 100644 --- a/version.py +++ b/version.py @@ -8,4 +8,4 @@ ZULIP_VERSION = "1.8.1+git" # Typically, adding a dependency only requires a minor version bump, and # removing a dependency requires a major version bump. -PROVISION_VERSION = '24.0' +PROVISION_VERSION = '24.1' diff --git a/zerver/lib/emoji.py b/zerver/lib/emoji.py index 55b7cf646a..7d6878b43e 100644 --- a/zerver/lib/emoji.py +++ b/zerver/lib/emoji.py @@ -11,20 +11,19 @@ from zerver.lib.request import JsonableError from zerver.lib.upload import upload_backend from zerver.models import Reaction, Realm, RealmEmoji, UserProfile -NAME_TO_CODEPOINT_PATH = os.path.join(settings.STATIC_ROOT, "generated", "emoji", "name_to_codepoint.json") -CODEPOINT_TO_NAME_PATH = os.path.join(settings.STATIC_ROOT, "generated", "emoji", "codepoint_to_name.json") +EMOJI_PATH = os.path.join(settings.STATIC_ROOT, "generated", "emoji") +NAME_TO_CODEPOINT_PATH = os.path.join(EMOJI_PATH, "name_to_codepoint.json") +CODEPOINT_TO_NAME_PATH = os.path.join(EMOJI_PATH, "codepoint_to_name.json") +EMOTICON_CONVERSIONS_PATH = os.path.join(EMOJI_PATH, "emoticon_conversions.json") -# Emoticons and which emoji they should become. Duplicate emoji are allowed. -# Changes here should be mimicked in `static/js/emoji.js` -# and `templates/zerver/help/enable-emoticon-translations.md`. -EMOTICON_CONVERSIONS = { - ':)': ':smiley:', - '(:': ':smiley:', - ':(': ':slight_frown:', - '<3': ':heart:', - ':|': ':expressionless:', - ':/': ':confused:', -} +with open(NAME_TO_CODEPOINT_PATH) as fp: + name_to_codepoint = ujson.load(fp) + +with open(CODEPOINT_TO_NAME_PATH) as fp: + codepoint_to_name = ujson.load(fp) + +with open(EMOTICON_CONVERSIONS_PATH) as fp: + EMOTICON_CONVERSIONS = ujson.load(fp) possible_emoticons = EMOTICON_CONVERSIONS.keys() possible_emoticon_regexes = map(re.escape, possible_emoticons) # type: ignore # AnyStr/str issues @@ -42,12 +41,6 @@ def translate_emoticons(text: str) -> str: return translated -with open(NAME_TO_CODEPOINT_PATH) as fp: - name_to_codepoint = ujson.load(fp) - -with open(CODEPOINT_TO_NAME_PATH) as fp: - codepoint_to_name = ujson.load(fp) - def emoji_name_to_emoji_code(realm: Realm, emoji_name: str) -> Tuple[str, str]: realm_emojis = realm.get_active_emoji() realm_emoji = realm_emojis.get(emoji_name)