diff --git a/webapp_post.py b/webapp_post.py
index f92dbfedb..5d2f1ea1c 100644
--- a/webapp_post.py
+++ b/webapp_post.py
@@ -42,7 +42,6 @@ from textmode import text_mode_removals
from quote import get_quote_toot_url
from timeFunctions import date_from_string_format
from timeFunctions import convert_published_to_local_timezone
-from utils import chatbot_nicknames
from utils import get_mutuals_of_person
from utils import save_json
from utils import remove_header_tags
@@ -107,6 +106,7 @@ from content import add_auto_cw
from person import is_person_snoozed
from person import get_person_avatar_url
from textmode import text_mode_browser
+from webapp_utils import get_display_name_prefix
from webapp_utils import get_show_map_button
from webapp_utils import mitm_warning_html
from webapp_utils import get_buy_links
@@ -1578,15 +1578,8 @@ def _get_post_title_announce_html(base_dir: str,
mutual_prefix = '⇆ '
actor_type = get_actor_type(base_dir, attributed_to, person_cache)
- bot_prefix = ''
- if actor_type:
- if actor_type in ('Organization', 'Organisation'):
- bot_prefix = '[' + translate['Organisation'] + '] '
- elif actor_type == 'Group':
- bot_prefix = '[' + translate['Group'] + '] '
- elif (actor_type != 'Person' or
- announce_nickname in chatbot_nicknames()):
- bot_prefix = '[' + translate['Bot'] + '] '
+ bot_prefix = get_display_name_prefix(actor_type, announce_nickname,
+ translate)
_log_post_timing(enable_timing_log, post_start_time, '13.3.1')
announce_display_name2 = \
@@ -1735,18 +1728,11 @@ def _get_reply_html(translate: {},
if reply_handle in mutuals_list:
mutual_prefix = '⇆ '
- bot_prefix = ''
- if actor_type:
- reply_nickname = ''
- if '@' in reply_nickname:
- reply_nickname = reply_handle.split('@')[0]
- if actor_type in ('Organization', 'Organisation'):
- bot_prefix = '[' + translate['Organisation'] + '] '
- elif actor_type == 'Group':
- bot_prefix = '[' + translate['Group'] + '] '
- elif (actor_type != 'Person' or
- reply_nickname in chatbot_nicknames()):
- bot_prefix = '[' + translate['Bot'] + '] '
+ reply_nickname = ''
+ if '@' in reply_nickname:
+ reply_nickname = reply_handle.split('@')[0]
+ bot_prefix = get_display_name_prefix(actor_type, reply_nickname,
+ translate)
replying_to_str = _replying_to_with_scope(post_json_object, translate)
post_bookmark = '#' + bookmark_from_id(in_reply_to)
@@ -2705,15 +2691,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
mutual_prefix = '⇆ '
actor_type = get_actor_type(base_dir, post_actor, person_cache)
- bot_prefix = ''
- if actor_type:
- if actor_type in ('Organization', 'Organisation'):
- bot_prefix = '[' + translate['Organisation'] + '] '
- elif actor_type == 'Group':
- bot_prefix = '[' + translate['Group'] + '] '
- elif (actor_type != 'Person' or
- actor_nickname in chatbot_nicknames()):
- bot_prefix = '[' + translate['Bot'] + '] '
+ bot_prefix = get_display_name_prefix(actor_type, actor_nickname,
+ translate)
if display_name:
display_name = _enforce_max_display_name_length(display_name)
diff --git a/webapp_utils.py b/webapp_utils.py
index 14bdec8fe..9b5ad8075 100644
--- a/webapp_utils.py
+++ b/webapp_utils.py
@@ -15,6 +15,7 @@ from session import get_json_valid
from flags import is_float
from flags import is_moderator
from formats import media_file_mime_type
+from utils import chatbot_nicknames
from utils import replace_strings
from utils import get_image_file
from utils import data_dir
@@ -2528,3 +2529,22 @@ def mitm_warning_html(translate: {}) -> str:
mitm_warning_str + '" alt="' + \
mitm_warning_str + '" src="/icons' + \
'/mitm.png" class="mitm"/>\n'
+
+
+def get_display_name_prefix(actor_type: str,
+ nickname: str,
+ translate: {}) -> str:
+ """Returns a prefix prepended to the display name to indicate that
+ an account is a bot, organisation or group
+ """
+ if not actor_type:
+ return ''
+ display_name_prefix = ''
+ if actor_type in ('Organization', 'Organisation'):
+ display_name_prefix = '[' + translate['Organisation'] + '] '
+ elif actor_type == 'Group':
+ display_name_prefix = '[' + translate['Group'] + '] '
+ elif (actor_type != 'Person' or
+ nickname in chatbot_nicknames()):
+ display_name_prefix = '[' + translate['Bot'] + '] '
+ return display_name_prefix