From f1d7d07d3b90d4f54a4c0182c34c1fcdfbf81836 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 18 Apr 2022 23:19:27 +0100 Subject: [PATCH] Show common emoji on search screen --- webapp_search.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/webapp_search.py b/webapp_search.py index 1213593c3..6936a9f01 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -330,6 +330,42 @@ def html_search_shared_items(css_cache: {}, translate: {}, return shared_items_form +def _html_common_emoji(base_dir: str, no_of_emoji: int) -> str: + """Shows common emoji + """ + common_emoji_filename = base_dir + '/accounts/common_emoji.txt' + if not os.path.isfile(common_emoji_filename): + return '' + common_emoji = None + try: + with open(common_emoji_filename, 'r') as fp_emoji: + common_emoji = fp_emoji.readlines() + except OSError: + print('EX: html_common_emoji unable to load file') + return '' + if not common_emoji: + return '' + line_ctr = 0 + ctr = 0 + html_str = '' + while ctr < no_of_emoji and ctr < len(common_emoji): + emoji_name = common_emoji[ctr].split(' ')[1].replace('\n', '') + 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 + html_str += \ + '
' + \ + '
:' + emoji_name + ':
\n' + ctr += 1 + line_ctr += 1 + if html_str: + html_str = \ + '
' + html_str + '
\n' + return html_str + + def html_search_emoji_text_entry(css_cache: {}, translate: {}, base_dir: str, path: str) -> str: """Search for an emoji by name @@ -367,6 +403,7 @@ def html_search_emoji_text_entry(css_cache: {}, translate: {}, ' \n' emoji_str += ' \n' + emoji_str += _html_common_emoji(base_dir, 8) emoji_str += ' \n' emoji_str += ' \n' emoji_str += '\n'