Check for multiple emoji display name

merge-requests/30/head
Bob Mottram 2022-05-02 23:50:14 +01:00
parent 2acbf60cf9
commit 21a6e1559a
2 changed files with 9 additions and 28 deletions

View File

@ -1025,7 +1025,13 @@ def display_name_is_emoji(display_name: str) -> bool:
"""Returns true if the given display name is an emoji
"""
if ' ' in display_name:
return False
words = display_name.split(' ')
for wrd in words:
if not wrd.startswith(':'):
return False
if not wrd.endswith(':'):
return False
return True
if len(display_name) < 2:
return False
if not display_name.startswith(':'):

View File

@ -1143,17 +1143,13 @@ def _get_post_title_announce_html(base_dir: str,
container_class_icons, container_class)
def _reply_to_yourself_html(actor: str, display_name: str,
translate: {}) -> str:
def _reply_to_yourself_html(translate: {}) -> str:
"""Returns html for a title which is a reply to yourself
"""
replying_to_themselves_str = 'replying to themselves'
if translate.get(replying_to_themselves_str):
replying_to_themselves_str = translate[replying_to_themselves_str]
title_str = \
' <a href="' + actor + \
'" class="announceOrReply"><span itemprop="author">' + \
display_name + '</span></a>\n' + \
' <img loading="lazy" decoding="async" title="' + \
replying_to_themselves_str + \
'" alt="' + replying_to_themselves_str + \
@ -1263,28 +1259,7 @@ def _get_post_title_reply_html(base_dir: str,
# reply to self
if obj_json['inReplyTo'].startswith(post_actor):
# get the display name for the poster replying to themselves
self_display_name = \
get_display_name(base_dir, post_actor, person_cache)
if self_display_name:
if len(self_display_name) < 2 or \
display_name_is_emoji(self_display_name):
self_display_name = None
if not self_display_name:
self_nickname = get_nickname_from_actor(post_actor)
self_domain, _ = get_domain_from_actor(post_actor)
if self_nickname and self_domain:
self_display_name = self_nickname + '@' + self_domain
else:
self_display_name = ''
# add emoji to the display name
if ':' in self_display_name:
self_display_name = \
add_emoji_to_display_name(None, base_dir, http_prefix,
nickname, domain,
self_display_name, False)
title_str += \
_reply_to_yourself_html(post_actor, self_display_name, translate)
title_str += _reply_to_yourself_html(translate)
return (title_str, reply_avatar_image_in_post,
container_class_icons, container_class)