From aaf8b811dc71239720c347fdf59510aef403bec0 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 27 Aug 2022 09:10:14 +0200 Subject: [PATCH] Fix mention processing bug --- app/actor.py | 17 +++++++++++++++-- app/boxes.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/actor.py b/app/actor.py index 049369e..3766588 100644 --- a/app/actor.py +++ b/app/actor.py @@ -154,9 +154,9 @@ async def save_actor(db_session: AsyncSession, ap_actor: ap.RawObject) -> "Actor raise ValueError(f"Invalid type {ap_type} for actor {ap_actor}") actor = models.Actor( - ap_id=ap_actor["id"], + ap_id=ap.get_id(ap_actor["id"]), ap_actor=ap_actor, - ap_type=ap_actor["type"], + ap_type=ap.as_list(ap_actor["type"])[0], handle=_handle(ap_actor), ) db_session.add(actor) @@ -188,6 +188,19 @@ async def fetch_actor( else: if save_if_not_found: ap_actor = await ap.fetch(actor_id) + # Some softwares uses URL when we expect ID + if actor_id == ap_actor.get("url"): + # Which mean we may already have it in DB + existing_actor_by_url = ( + await db_session.scalars( + select(models.Actor).where( + models.Actor.ap_id == ap.get_id(ap_actor), + ) + ) + ).one_or_none() + if existing_actor_by_url: + return existing_actor_by_url + return await save_actor(db_session, ap_actor) else: raise ap.ObjectNotFoundError diff --git a/app/boxes.py b/app/boxes.py index 3b1f55c..06a5f53 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -351,7 +351,7 @@ async def fetch_conversation_root( db_session, ap.get_actor_id(raw_reply) ) in_reply_to_object = RemoteObject(raw_reply, actor=raw_reply_actor) - except (ap.ObjectNotFoundError, ap.ObjectIsGoneError): + except (ap.ObjectNotFoundError, ap.ObjectIsGoneError, ap.NotAnObjectError): return await fetch_conversation_root(db_session, obj, is_root=True) except httpx.HTTPStatusError as http_status_error: if 400 <= http_status_error.response.status_code < 500: