diff --git a/utils.py b/utils.py index 3747c7684..d2337b39f 100644 --- a/utils.py +++ b/utils.py @@ -23,6 +23,8 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes from followingCalendar import add_person_to_calendar +MAX_STATUS_LENGTH = 100 + VALID_HASHTAG_CHARS = \ set('_0123456789' + 'abcdefghijklmnopqrstuvwxyz' + @@ -5556,10 +5558,17 @@ def get_actor_status(profile_json: {}) -> str: """ if not profile_json.get('sm:status'): return '' + status = '' if isinstance(profile_json['sm:status'], str): - return profile_json['sm:status'] - if isinstance(profile_json['sm:status'], dict): + status = profile_json['sm:status'] + elif isinstance(profile_json['sm:status'], dict): if profile_json['sm:status'].get('content'): - if isinstance(profile_json['sm:status']['content'], str): - return profile_json['sm:status']['content'] - return '' + possible_status = profile_json['sm:status']['content'] + if isinstance(status, str): + status = possible_status + if status: + status = remove_html(status) + if len(status) > MAX_STATUS_LENGTH: + status = status[:MAX_STATUS_LENGTH] + status = standardize_text(status) + return status diff --git a/webapp_person_options.py b/webapp_person_options.py index 72e9f401f..ce01ad1c7 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -14,7 +14,6 @@ from person import is_person_snoozed from posts import is_moderator from flags import is_featured_writer from flags import is_dormant -from utils import standardize_text from utils import data_dir from utils import quote_toots_allowed from utils import get_full_domain @@ -403,16 +402,14 @@ def html_person_options(default_timeline: str, if status: # https://codeberg.org/fediverse/fep/src/branch/main/ # fep/82f6/fep-82f6.md - if len(status) < 100: - status = standardize_text(status) - if is_filtered(base_dir, nickname, domain, status, - system_language): - status_str = 'Status' - if translate.get('Status'): - status_str = translate['Status'] - options_str += \ - '
' + status_str + ': ' + \ - remove_html(status) + '
\n' + if is_filtered(base_dir, nickname, domain, status, + system_language): + status_str = 'Status' + if translate.get('Status'): + status_str = translate['Status'] + options_str += \ + '' + status_str + ': ' + \ + remove_html(status) + '
\n' if pronouns: options_str += \ '' + translate['Pronouns'] + \ diff --git a/webapp_profile.py b/webapp_profile.py index ad5cbf544..b1386bd59 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -364,15 +364,12 @@ def html_profile_after_search(authorized: bool, profile_status = get_actor_status(profile_json) if profile_status: - profile_status = remove_html(profile_status) - if len(profile_status) < 100: - profile_status = standardize_text(profile_status) - profile_status = \ - remove_link_trackers_from_content(profile_status) - profile_status = \ - add_emoji_to_display_name(session, base_dir, http_prefix, - nickname, domain, - profile_status, False, translate) + profile_status = \ + remove_link_trackers_from_content(profile_status) + profile_status = \ + add_emoji_to_display_name(session, base_dir, http_prefix, + nickname, domain, + profile_status, False, translate) profile_description = '' if profile_json.get('summary'): if not dangerous_markup(profile_json['summary'], @@ -1124,15 +1121,12 @@ def html_profile(signing_priv_key_pem: str, domain_full = get_full_domain(domain, port) profile_status = get_actor_status(profile_json) if profile_status: - profile_status = remove_html(profile_status) - if len(profile_status) < 100: - profile_status = standardize_text(profile_status) - profile_status = \ - remove_link_trackers_from_content(profile_status) - profile_status = \ - add_emoji_to_display_name(session, base_dir, http_prefix, - nickname, domain, - profile_status, False, translate) + profile_status = \ + remove_link_trackers_from_content(profile_status) + profile_status = \ + add_emoji_to_display_name(session, base_dir, http_prefix, + nickname, domain, + profile_status, False, translate) if not dangerous_markup(profile_json['summary'], False, []): profile_description = profile_json['summary'] else: