#!/usr/bin/env python3 from app import models from app.database import AsyncSession from loguru import logger from uuid import uuid4 async def save_incoming( db_session: AsyncSession, payload: dict, ) -> models.IncomingActivity | None: ap_id: str if "@context" not in payload: logger.warning(f"invalid object: {payload}") return None if "id" in payload: ap_id = payload["id"] else: ap_id = str(uuid4()) incoming_activity = models.IncomingActivity( ap_id=ap_id, ap_object=payload, ) db_session.add(incoming_activity) await db_session.commit() await db_session.refresh(incoming_activity) return incoming_activity