Check for actor status expiry

main
Bob Mottram 2025-05-17 11:16:52 +01:00
parent 8b5fc1a7ef
commit b5f406fecf
5 changed files with 51 additions and 0 deletions

View File

@ -12,6 +12,8 @@ import json
from roles import get_actor_roles_list
from skills import no_of_actor_skills
from skills import get_skills_from_list
from utils import get_actor_status
from utils import actor_status_expired
from utils import get_nickname_from_actor
from utils import load_json
from utils import get_json_content_from_accept
@ -171,6 +173,11 @@ def show_person_profile(self, authorized: bool,
if secure_mode(curr_session, proxy_type, False,
self.server, self.headers, self.path):
accept_str = self.headers['Accept']
# has the actor status expired?
if get_actor_status(actor_json):
if actor_status_expired(actor_json['sm:status']):
# remove actor status
del actor_json['sm:status']
msg_str = json.dumps(actor_json, ensure_ascii=False)
msg_str = convert_domains(calling_domain,
referer_domain,

View File

@ -26,6 +26,7 @@ from blocking import is_blocked_nickname
from blocking import is_blocked_domain
from content import valid_url_lengths
from posts import add_to_field
from utils import actor_status_expired
from utils import get_actor_status
from utils import detect_mitm
from utils import data_dir
@ -704,6 +705,9 @@ def show_person_options(self, calling_domain: str, path: str,
also_known_as = remove_html(actor_json['alsoKnownAs'])
repo_url = get_repo_url(actor_json)
status = get_actor_status(actor_json)
if status:
if actor_status_expired(actor_json['sm:status']):
status = ''
access_keys = self.server.access_keys
nickname = 'instance'

View File

@ -11,6 +11,7 @@ import os
import time
from flags import is_recent_post
from flags import is_quote_toot
from utils import actor_status_expired
from utils import get_quote_toot_url
from utils import get_actor_from_post_id
from utils import contains_invalid_actor_url_chars
@ -1136,6 +1137,9 @@ def receive_actor_status(base_dir: str, person_cache: {}, message_json: {},
if not actor_json:
print('DEBUG: receive_actor_status actor not found ' + actor_url)
return True
if actor_status_expired(message_json):
print('DEBUG: receive_actor_status expired ' + str(message_json))
return True
actor_json['sm:status'] = message_json
allow_write_to_file = True
store_person_in_cache(base_dir, actor_url,

View File

@ -5574,3 +5574,32 @@ def get_actor_status(profile_json: {}) -> str:
status = status[:MAX_STATUS_LENGTH]
status = standardize_text(status)
return status
def actor_status_expired(actor_status_json: {}) -> bool:
"""Has the given actor status expired?
"""
if not actor_status_json.get('endTime'):
return False
if not isinstance(actor_status_json['endTime'], str):
return False
if 'T' not in actor_status_json['endTime'] or \
':' not in actor_status_json['endTime']:
return False
date_formats = (
"%Y-%m-%dT%H:%M:%S%z",
"%Y-%m-%dT%H:%M:%S%Z"
)
status_end_time = None
try:
status_end_time = \
date_from_string_format(actor_status_json['endTime'],
date_formats)
except BaseException:
return False
if not status_end_time:
return False
curr_time = date_utcnow()
if status_end_time < curr_time:
return True
return False

View File

@ -16,6 +16,7 @@ from flags import is_system_account
from flags import is_group_account
from flags import is_valid_date
from flags import is_premium_account
from utils import actor_status_expired
from utils import get_actor_status
from utils import get_person_icon
from utils import text_mode_removals
@ -365,6 +366,9 @@ def html_profile_after_search(authorized: bool,
search_domain_full)
profile_status = get_actor_status(profile_json)
if profile_status:
if actor_status_expired(profile_json['sm:status']):
profile_status = ''
if profile_status:
profile_status = \
remove_link_trackers_from_content(profile_status)
@ -1137,6 +1141,9 @@ def html_profile(signing_priv_key_pem: str,
display_name, False, translate)
domain_full = get_full_domain(domain, port)
profile_status = get_actor_status(profile_json)
if profile_status:
if actor_status_expired(profile_json['sm:status']):
profile_status = ''
if profile_status:
profile_status = \
remove_link_trackers_from_content(profile_status)