Truncate status strings if needed

main
Bob Mottram 2025-05-16 10:38:24 +01:00
parent 351b45b282
commit 9908896ada
3 changed files with 34 additions and 34 deletions

View File

@ -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

View File

@ -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 += \
' <p class="imText">' + status_str + ': ' + \
remove_html(status) + '</p>\n'
if is_filtered(base_dir, nickname, domain, status,
system_language):
status_str = 'Status'
if translate.get('Status'):
status_str = translate['Status']
options_str += \
' <p class="imText">' + status_str + ': ' + \
remove_html(status) + '</p>\n'
if pronouns:
options_str += \
' <p class="imText">' + translate['Pronouns'] + \

View File

@ -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: