[feat] process like activity
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
SouthFox 2023-05-08 14:50:13 +08:00
parent 0d690add79
commit a4014e85c7

View file

@ -194,6 +194,23 @@ async def process_incoming(
relates_to_inbox_object=relates_to_inbox_object, relates_to_inbox_object=relates_to_inbox_object,
): ):
return True return True
elif "Like" == ap_object["type"]:
inbox_object = build_object(
ap_object,
relates_to_inbox_object=relates_to_inbox_object,
relates_to_outbox_object=relates_to_outbox_object,
)
db_session.add(inbox_object)
await db_session.flush()
await db_session.refresh(inbox_object)
if await _handle_like(
db_session,
inbox_object,
relates_to_outbox_object=relates_to_outbox_object,
relates_to_inbox_object=relates_to_inbox_object,
):
return True
return False return False
@ -311,7 +328,7 @@ async def _handle_announce(
relates_to_inbox_object: models.InboxObject | None, relates_to_inbox_object: models.InboxObject | None,
) -> bool : ) -> bool :
if relates_to_outbox_object: if relates_to_outbox_object:
relates_to_outbox_object.announces_count = ( relates_to_outbox_object.announces_count = ( # type: ignore
models.OutboxObject.announces_count + 1 models.OutboxObject.announces_count + 1
) )
logger.info(f"announces +1 {relates_to_outbox_object.ap_id}") logger.info(f"announces +1 {relates_to_outbox_object.ap_id}")
@ -320,6 +337,22 @@ async def _handle_announce(
return False return False
async def _handle_like(
db_session: AsyncSession,
inbox_object: InboxObject,
relates_to_outbox_object: models.OutboxObject | None,
relates_to_inbox_object: models.InboxObject | None,
) -> bool :
if relates_to_outbox_object:
relates_to_outbox_object.likes_count = ( # type: ignore
models.OutboxObject.likes_count + 1
)
logger.info(f"likes +1 {relates_to_outbox_object.ap_id}")
return True
else:
return False
async def _send_follow( async def _send_follow(
db_session : AsyncSession, db_session : AsyncSession,
actor_url : str, actor_url : str,