parent
e8ec99c77a
commit
a072d89cad
2 changed files with 53 additions and 0 deletions
|
@ -132,6 +132,7 @@ async def process_incoming(
|
||||||
db_session.add(following)
|
db_session.add(following)
|
||||||
await db_session.flush()
|
await db_session.flush()
|
||||||
await db_session.refresh(following)
|
await db_session.refresh(following)
|
||||||
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
52
tasks.py
52
tasks.py
|
@ -77,3 +77,55 @@ def follow(ctx):
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(_dodo())
|
asyncio.run(_dodo())
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def accept_follow(ctx):
|
||||||
|
from app.database import async_session
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import joinedload
|
||||||
|
from app import models
|
||||||
|
from app.boxes import _send_accept
|
||||||
|
|
||||||
|
ingress_id = prompt("enter want to accept ingress id:")
|
||||||
|
|
||||||
|
async def _do():
|
||||||
|
async with async_session() as db_session: #type: ignore
|
||||||
|
try:
|
||||||
|
|
||||||
|
exist_request = (
|
||||||
|
await db_session.scalars(
|
||||||
|
select(models.IncomingActivity).where(
|
||||||
|
models.IncomingActivity.id == int(ingress_id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).one_or_none()
|
||||||
|
|
||||||
|
if not exist_request or exist_request.ap_object["type"] != "Follow":
|
||||||
|
raise ValueError("Non-valid id!")
|
||||||
|
|
||||||
|
exist_inbox = (
|
||||||
|
await db_session.scalars(
|
||||||
|
select(models.InboxObject).where(
|
||||||
|
models.InboxObject.ap_id == exist_request.ap_id
|
||||||
|
).options(
|
||||||
|
joinedload(models.InboxObject.actor)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).one_or_none()
|
||||||
|
|
||||||
|
await _send_accept(
|
||||||
|
db_session,
|
||||||
|
exist_inbox.actor,
|
||||||
|
exist_inbox,
|
||||||
|
)
|
||||||
|
await db_session.delete(exist_request)
|
||||||
|
await db_session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: Failed to {e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(_do())
|
||||||
|
|
Loading…
Reference in a new issue