mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-21 20:54:27 +00:00
Improve Accept/Reject for Follow
This commit is contained in:
parent
e3a02a8138
commit
228de1b83a
1 changed files with 20 additions and 7 deletions
27
app/boxes.py
27
app/boxes.py
|
@ -1766,13 +1766,6 @@ async def save_to_inbox(
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if relates_to_outbox_object.ap_type == "Follow":
|
if relates_to_outbox_object.ap_type == "Follow":
|
||||||
following = models.Following(
|
|
||||||
actor_id=actor.id,
|
|
||||||
outbox_object_id=relates_to_outbox_object.id,
|
|
||||||
ap_actor_id=actor.ap_id,
|
|
||||||
)
|
|
||||||
db_session.add(following)
|
|
||||||
|
|
||||||
notif_type = (
|
notif_type = (
|
||||||
models.NotificationType.FOLLOW_REQUEST_ACCEPTED
|
models.NotificationType.FOLLOW_REQUEST_ACCEPTED
|
||||||
if activity_ro.ap_type == "Accept"
|
if activity_ro.ap_type == "Accept"
|
||||||
|
@ -1784,9 +1777,29 @@ async def save_to_inbox(
|
||||||
inbox_object_id=inbox_object.id,
|
inbox_object_id=inbox_object.id,
|
||||||
)
|
)
|
||||||
db_session.add(notif)
|
db_session.add(notif)
|
||||||
|
|
||||||
if activity_ro.ap_type == "Accept":
|
if activity_ro.ap_type == "Accept":
|
||||||
|
following = models.Following(
|
||||||
|
actor_id=actor.id,
|
||||||
|
outbox_object_id=relates_to_outbox_object.id,
|
||||||
|
ap_actor_id=actor.ap_id,
|
||||||
|
)
|
||||||
|
db_session.add(following)
|
||||||
|
|
||||||
# Pre-fetch the latest activities
|
# Pre-fetch the latest activities
|
||||||
await _prefetch_actor_outbox(db_session, actor)
|
await _prefetch_actor_outbox(db_session, actor)
|
||||||
|
elif activity_ro.ap_type == "Reject":
|
||||||
|
maybe_following = (
|
||||||
|
await db_session.scalars(
|
||||||
|
select(models.Following).where(
|
||||||
|
models.Following.ap_actor_id == actor.ap_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).one_or_none()
|
||||||
|
if maybe_following:
|
||||||
|
logger.info("Removing actor from following")
|
||||||
|
await db_session.delete(maybe_following)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Received an Accept for an unsupported activity: "
|
"Received an Accept for an unsupported activity: "
|
||||||
|
|
Loading…
Reference in a new issue