emoji: Move EMOTICON_CONVERSIONS mapping to build_emoji infra.

This commit closes a long pending issue which involved moving the
`EMOTICON_CONVERSION` mapping to build_emoji infrastructure so
that there is only one source of truth. This was pending from the
time when this feature was implemented.
This commit is contained in:
Harshit Bansal
2018-07-20 09:37:39 +00:00
committed by Tim Abbott
parent 565fd75661
commit c0b0fb7cce
6 changed files with 39 additions and 38 deletions

View File

@@ -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)

View File

@@ -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():