Start support for processing transient object

main
Thomas Sileo 2022-07-15 08:40:07 +02:00
parent 8dc0e1877b
commit 4f16e3b940
3 changed files with 35 additions and 3 deletions

View File

@ -836,6 +836,20 @@ async def _process_note_object(
db_session.add(notif)
async def _process_transient_object(
db_session: AsyncSession,
raw_object: ap.RawObject,
from_actor: models.Actor,
) -> None:
ap_type = raw_object["type"]
if ap_type in ["Add", "Remove"]:
logger.info(f"Dropping unsupported {ap_type} object")
else:
logger.warning(f"Received unknown {ap_type} object")
return None
async def save_to_inbox(
db_session: AsyncSession,
raw_object: ap.RawObject,
@ -847,6 +861,10 @@ async def save_to_inbox(
logger.exception("Failed to fetch actor")
return
if "id" not in raw_object:
await _process_transient_object(db_session, raw_object, actor)
return None
raw_object_id = ap.get_id(raw_object)
# Ensure forwarded activities have a valid LD sig

View File

@ -9,6 +9,7 @@ from sqlalchemy import select
from app import activitypub as ap
from app import httpsig
from app import ldsig
from app import models
from app.boxes import save_to_inbox
from app.database import AsyncSession
@ -22,10 +23,23 @@ async def new_ap_incoming_activity(
db_session: AsyncSession,
httpsig_info: httpsig.HTTPSigInfo,
raw_object: ap.RawObject,
) -> models.IncomingActivity:
) -> models.IncomingActivity | None:
ap_id: str
if "id" not in raw_object:
if "@context" not in raw_object:
logger.warning(f"Dropping invalid object: {raw_object}")
return None
else:
# This is a transient object, Build the JSON LD hash as the ID
ap_id = ldsig._doc_hash(raw_object)
else:
ap_id = ap.get_id(raw_object)
# TODO(ts): dedup first
incoming_activity = models.IncomingActivity(
sent_by_ap_actor_id=httpsig_info.signed_by_ap_actor_id,
ap_id=ap.get_id(raw_object),
ap_id=ap_id,
ap_object=raw_object,
)
db_session.add(incoming_activity)

View File

@ -72,7 +72,7 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac
# TODO(ts):
#
# Next:
# - incoming activity worker
# - fix stream (only content from follows + mention, and dedup shares)
# - handle remove activity
# - retries httpx?
# - DB models for webmentions