Fix mention processing bug

This commit is contained in:
Thomas Sileo 2022-08-27 09:10:14 +02:00
parent 4e445a7207
commit aaf8b811dc
2 changed files with 16 additions and 3 deletions

View file

@ -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}") raise ValueError(f"Invalid type {ap_type} for actor {ap_actor}")
actor = models.Actor( actor = models.Actor(
ap_id=ap_actor["id"], ap_id=ap.get_id(ap_actor["id"]),
ap_actor=ap_actor, ap_actor=ap_actor,
ap_type=ap_actor["type"], ap_type=ap.as_list(ap_actor["type"])[0],
handle=_handle(ap_actor), handle=_handle(ap_actor),
) )
db_session.add(actor) db_session.add(actor)
@ -188,6 +188,19 @@ async def fetch_actor(
else: else:
if save_if_not_found: if save_if_not_found:
ap_actor = await ap.fetch(actor_id) 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) return await save_actor(db_session, ap_actor)
else: else:
raise ap.ObjectNotFoundError raise ap.ObjectNotFoundError

View file

@ -351,7 +351,7 @@ async def fetch_conversation_root(
db_session, ap.get_actor_id(raw_reply) db_session, ap.get_actor_id(raw_reply)
) )
in_reply_to_object = RemoteObject(raw_reply, actor=raw_reply_actor) 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) return await fetch_conversation_root(db_session, obj, is_root=True)
except httpx.HTTPStatusError as http_status_error: except httpx.HTTPStatusError as http_status_error:
if 400 <= http_status_error.response.status_code < 500: if 400 <= http_status_error.response.status_code < 500: