From cf14b186c1508189f96a7cabcf68fa1772e9a263 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:19:10 +1300 Subject: [PATCH] sometimes attributedTo is a list of strings --- app/activitypub/util.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 43e812af..2eda155b 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -2217,18 +2217,23 @@ def ensure_domains_match(activity: dict) -> bool: if 'id' in activity: note_id = activity['id'] else: - note_id = None + note_id = None note_actor = None if 'actor' in activity: note_actor = activity['actor'] - elif 'attributedTo' in activity and isinstance(activity['attributedTo'], str): - note_actor = activity['attributedTo'] - elif 'attributedTo' in activity and isinstance(activity['attributedTo'], list): - for a in activity['attributedTo']: - if a['type'] == 'Person': - note_actor = a['id'] - break + elif 'attributedTo' in activity: + attributed_to = activity['attributedTo'] + if isinstance(attributed_to, str): + note_actor = attributed_to + elif isinstance(attributed_to, list): + for a in attributed_to: + if isinstance(a, dict) and a.get('type') == 'Person': + note_actor = a.get('id') + break + elif isinstance(a, str): + note_actor = a + break if note_id and note_actor: parsed_url = urlparse(note_id)