From 722350c6a7537126f639331d7cf20bd465932054 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 29 May 2024 20:03:41 +0100 Subject: [PATCH] Tidying --- webapp_post.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/webapp_post.py b/webapp_post.py index 8807dac2e..278a256f4 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -131,6 +131,14 @@ from session import get_json MAX_DISPLAY_NAME_LENGTH = 42 +def _bookmark_from_id(post_id: str) -> str: + """ Converts a post id into a bookmark + """ + timeline_post_bookmark = remove_id_ending(post_id) + timeline_post_bookmark = timeline_post_bookmark.replace('://', '-') + return timeline_post_bookmark.replace('/', '-') + + def _enforce_max_display_name_length(display_name: str) -> str: """Ensures that the display name does not get too long """ @@ -1338,7 +1346,7 @@ def _announce_unattributed_html(translate: {}, if translate.get(announces_str): announces_str = translate[announces_str] post_id = remove_id_ending(post_json_object['object']['id']) - post_bookmark = '#' + post_id.replace('://', '-').replace('/', '-') + post_bookmark = '#' + _bookmark_from_id(post_id) post_link = '/users/' + nickname + '?convthread=' + \ post_id.replace('--', '/') + post_bookmark return ' ' + avatar_link + '\n' - timeline_post_bookmark = remove_id_ending(post_json_object['id']) - timeline_post_bookmark = timeline_post_bookmark.replace('://', '-') - timeline_post_bookmark = timeline_post_bookmark.replace('/', '-') + timeline_post_bookmark = _bookmark_from_id(post_json_object['id']) # If this is the inbox timeline then don't show the repeat icon on any DMs show_repeat_icon = show_repeats @@ -2709,8 +2714,7 @@ def individual_post_as_html(signing_priv_key_pem: str, if content_license_url and not is_reminder(post_json_object): footer_str += _get_copyright_footer(content_license_url, translate) - post_bookmark = \ - '#' + published_link.replace('://', '-').replace('/', '-') + post_bookmark = '#' + _bookmark_from_id(published_link) conv_link = '/users/' + nickname + '?convthread=' + \ published_link.replace('--', '/') + post_bookmark footer_str += '