From bd4d5a004a4909a6072d16f4b49e450f797b9f8c Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Tue, 13 Sep 2022 07:59:35 +0200 Subject: [PATCH] Improve Announce handling --- app/boxes.py | 9 ++++++++- app/lookup.py | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/boxes.py b/app/boxes.py index a6fd090..95ed640 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -1783,6 +1783,12 @@ async def _handle_announce_activity( announced_raw_object = await ap.fetch( announce_activity.activity_object_ap_id ) + + # Some software return objects wrapped in a Create activity (like + # python-federation) + if ap.as_list(announced_raw_object["type"])[0] == "Create": + announced_raw_object = await ap.get_object(announced_raw_object) + announced_actor = await fetch_actor( db_session, ap.get_actor_id(announced_raw_object) ) @@ -1844,6 +1850,7 @@ async def _process_transient_object( if ap_type in ["Add", "Remove"]: logger.info(f"Dropping unsupported {ap_type} object") else: + # FIXME(ts): handle transient create logger.warning(f"Received unknown {ap_type} object") return None @@ -1867,7 +1874,7 @@ async def save_to_inbox( logger.warning(f"Server {actor.server} is blocked") return - if "id" not in raw_object: + if "id" not in raw_object or not raw_object["id"]: await _process_transient_object(db_session, raw_object, actor) return None diff --git a/app/lookup.py b/app/lookup.py index 7be3cff..c1b6ef1 100644 --- a/app/lookup.py +++ b/app/lookup.py @@ -38,4 +38,9 @@ async def lookup(db_session: AsyncSession, query: str) -> Actor | RemoteObject: if ap.as_list(ap_obj["type"])[0] in ap.ACTOR_TYPES: return RemoteActor(ap_obj) else: + # Some software return objects wrapped in a Create activity (like + # python-federation) + if ap.as_list(ap_obj["type"])[0] == "Create": + ap_obj = await ap.get_object(ap_obj) + return await RemoteObject.from_raw_object(ap_obj)