Improve Announce handling

This commit is contained in:
Thomas Sileo 2022-09-13 07:59:35 +02:00
parent 04da8725ed
commit bd4d5a004a
2 changed files with 13 additions and 1 deletions

View file

@ -1783,6 +1783,12 @@ async def _handle_announce_activity(
announced_raw_object = await ap.fetch( announced_raw_object = await ap.fetch(
announce_activity.activity_object_ap_id 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( announced_actor = await fetch_actor(
db_session, ap.get_actor_id(announced_raw_object) db_session, ap.get_actor_id(announced_raw_object)
) )
@ -1844,6 +1850,7 @@ async def _process_transient_object(
if ap_type in ["Add", "Remove"]: if ap_type in ["Add", "Remove"]:
logger.info(f"Dropping unsupported {ap_type} object") logger.info(f"Dropping unsupported {ap_type} object")
else: else:
# FIXME(ts): handle transient create
logger.warning(f"Received unknown {ap_type} object") logger.warning(f"Received unknown {ap_type} object")
return None return None
@ -1867,7 +1874,7 @@ async def save_to_inbox(
logger.warning(f"Server {actor.server} is blocked") logger.warning(f"Server {actor.server} is blocked")
return 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) await _process_transient_object(db_session, raw_object, actor)
return None return None

View file

@ -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: if ap.as_list(ap_obj["type"])[0] in ap.ACTOR_TYPES:
return RemoteActor(ap_obj) return RemoteActor(ap_obj)
else: 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) return await RemoteObject.from_raw_object(ap_obj)