refactor/process boxes

This commit is contained in:
SouthFox 2023-03-18 16:12:44 +08:00
parent cde57f2604
commit 0ff423cf9b

View file

@ -37,7 +37,9 @@ async def save_incoming(
ap_object=payload, ap_object=payload,
) )
await process_incoming(db_session, payload) await process_incoming(db_session, payload)
db_session.add(incoming_activity) if db_session.add(incoming_activity):
return incoming_activity
await db_session.commit() await db_session.commit()
await db_session.refresh(incoming_activity) await db_session.refresh(incoming_activity)
return incoming_activity return incoming_activity
@ -50,23 +52,26 @@ async def process_incoming(
if "Follow" == ap_object["type"]: if "Follow" == ap_object["type"]:
await _handle_follow(db_session, ap_object) await _handle_follow(db_session, ap_object)
return True return True
return False
async def _handle_follow( async def _handle_follow(
db_session: AsyncSession, db_session: AsyncSession,
ap_object: dict, ap_object: dict,
) -> None: ) -> bool:
if ME["id"] != ap_object["object"]: if ME["id"] != ap_object["object"]:
# await db_session.delete(ap_object) # await db_session.delete(ap_object)
logger.warning("no match follow object!" + ap_object["object"]) logger.warning("no match follow object!" + ap_object["object"])
return return False
if MANUALLY_APPROVES_FOLLOWERS: if MANUALLY_APPROVES_FOLLOWERS:
# TODO # TODO
return return False
await _send_accept(db_session, ap_object) await _send_accept(db_session, ap_object)
return True
async def _send_accept( async def _send_accept(