From adf98ebf93ea738e0c8aef15c688924c7f06fb93 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 8 Jan 2023 21:41:44 +0000 Subject: [PATCH] Less strict checking of announce id --- inbox.py | 5 ++++- person.py | 3 ++- posts.py | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/inbox.py b/inbox.py index 499771d4b..afd1cfc5f 100644 --- a/inbox.py +++ b/inbox.py @@ -898,7 +898,8 @@ def _inbox_post_recipients(base_dir: str, post_json_object: {}, else: if debug and post_json_object.get('object'): if isinstance(post_json_object['object'], str): - if '/statuses/' in post_json_object['object']: + if '/statuses/' in post_json_object['object'] or \ + '/objects/' in post_json_object['object']: print('DEBUG: inbox item is a link to a post') else: if '/users/' in post_json_object['object']: @@ -2774,6 +2775,8 @@ def _receive_announce(recent_posts_cache: {}, if has_users_path(lookup_actor): if '/statuses/' in lookup_actor: lookup_actor = lookup_actor.split('/statuses/')[0] + elif '/objects/' in lookup_actor: + lookup_actor = lookup_actor.split('/objects/')[0] if is_recent_post(post_json_object, 3): if not os.path.isfile(post_filename + '.tts'): diff --git a/person.py b/person.py index 16abd7561..c574fcb1d 100644 --- a/person.py +++ b/person.py @@ -1199,7 +1199,8 @@ def can_remove_post(base_dir: str, domain: str, port: int, post_id: str) -> bool: """Returns true if the given post can be removed """ - if '/statuses/' not in post_id: + if '/statuses/' not in post_id and \ + '/objects/' not in post_id: return False domain_full = get_full_domain(domain, port) diff --git a/posts.py b/posts.py index 82997dc9d..21ffd879d 100644 --- a/posts.py +++ b/posts.py @@ -5240,6 +5240,9 @@ def download_announce(session, base_dir: str, http_prefix: str, base_dir, nickname, domain, post_id, recent_posts_cache) return None + announced_actor = announced_json['id'] + if announced_json.get('attributedTo'): + announced_actor = announced_json['attributedTo'] if not announced_json.get('type'): print('WARN: announced post does not have a type ' + str(announced_json)) @@ -5254,14 +5257,15 @@ def download_announce(session, base_dir: str, http_prefix: str, announced_json, blocked_cache) if converted_json: announced_json = converted_json - if '/statuses/' not in announced_json['id']: + if '/statuses/' not in announced_json['id'] and \ + '/objects/' not in announced_json['id']: print('WARN: announced post id does not contain /statuses/ ' + - str(announced_json)) + 'or /objects/' + str(announced_json)) _reject_announce(announce_filename, base_dir, nickname, domain, post_id, recent_posts_cache) return None - if not has_users_path(announced_json['id']): + if not has_users_path(announced_actor): print('WARN: announced post id does not contain /users/ ' + str(announced_json)) _reject_announce(announce_filename,