WIP/following feat

This commit is contained in:
SouthFox 2023-03-21 13:58:14 +08:00
parent fe09de3cd8
commit e251dca8ae
3 changed files with 52 additions and 2 deletions

View file

@ -24,8 +24,8 @@ class BaseActor:
return self.ap_actor["inbox"] return self.ap_actor["inbox"]
async def fetch_actor( async def fetch_actor(
actor_id : str,
db_session : AsyncSession, db_session : AsyncSession,
actor_id : str,
) -> Actor: ) -> Actor:
exist_actor = ( exist_actor = (
await db_session.scalars( await db_session.scalars(

View file

@ -69,7 +69,7 @@ async def process_incoming(
db_session: AsyncSession, db_session: AsyncSession,
ap_object: dict, ap_object: dict,
) -> bool: ) -> bool:
actor = await fetch_actor(ap_object["actor"], db_session) actor = await fetch_actor(db_session, ap_object["actor"])
def build_object(object) -> InboxObject: def build_object(object) -> InboxObject:
inbox_object = models.InboxObject( inbox_object = models.InboxObject(
@ -190,3 +190,31 @@ async def _handle_undo(
return True return True
return False return False
async def send_follow(
db_session : AsyncSession,
acct : str
):
await _send_follow(db_session, acct)
await db_session.commit()
await db_session.flush()
async def _send_follow(
db_session : AsyncSession,
actor_url : str,
):
actor = await fetch_actor(db_session, actor_url)
follow_id = allocate_outbox_id()
out = {
"@context": ap.AS_CTX,
"id": build_object_id(follow_id),
"type": "Follow",
"actor": ME["id"],
"object": actor.ap_id,
}
await ap.post(
actor.ap_actor["inbox"],
out,
)

View file

@ -1,6 +1,7 @@
import os import os
import sys import sys
import tomli_w import tomli_w
import asyncio
from pathlib import Path from pathlib import Path
@ -55,3 +56,24 @@ def config(ctx):
print("Done") print("Done")
sys.exit(0) sys.exit(0)
@task
def follow(ctx):
from app.database import async_session
from app.boxes import send_follow
acct = prompt("enter want to follow actor id:")
async def _dodo():
async with async_session() as db_session: #type: ignore
try:
await send_follow(db_session,acct)
except Exception as e:
print(f"ERROR: Failed to {e}")
return
print("Done!")
asyncio.run(_dodo())