From a7cb0ead44e116ee050276c5c7dfee6ae6ac1dcc Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 19 Apr 2022 15:18:54 +0100 Subject: [PATCH] Lookup emoji codes from their names for the common emoji list --- webapp_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/webapp_utils.py b/webapp_utils.py index 2c8ca2c25..8b414a7c3 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -1677,6 +1677,11 @@ def set_custom_background(base_dir: str, background: str, def html_common_emoji(base_dir: str, no_of_emoji: int) -> str: """Shows common emoji """ + emojis_filename = base_dir + '/emoji/emoji.json' + if not os.path.isfile(emojis_filename): + emojis_filename = base_dir + '/emoji/default_emoji.json' + emojis_json = None + common_emoji_filename = base_dir + '/accounts/common_emoji.txt' if not os.path.isfile(common_emoji_filename): return '' @@ -1695,6 +1700,18 @@ def html_common_emoji(base_dir: str, no_of_emoji: int) -> str: while ctr < no_of_emoji and line_ctr < len(common_emoji): emoji_name = common_emoji[line_ctr].split(' ')[1].replace('\n', '') emoji_filename = base_dir + '/emoji/' + emoji_name + '.png' + if not os.path.isfile(emoji_filename): + # load the emojis index + if not emojis_json: + emojis_json = load_json(emojis_filename) + # lookup the name within the index to get the hex code + if emojis_json: + for emoji_tag, emoji_code in emojis_json.items(): + if emoji_tag == emoji_name: + emoji_name = emoji_code + # get the filename based on the hex code + emoji_filename = \ + base_dir + '/emoji/' + emoji_name + '.png' if os.path.isfile(emoji_filename): # NOTE: deliberately no alt text, so that without graphics only # the emoji name shows