mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 13:39:17 +02:00
Resolve "Per-user libraries" (use !368 instead)
This commit is contained in:
parent
b0ca181016
commit
2ea21994ee
144 changed files with 6749 additions and 5347 deletions
78
api/funkwhale_api/federation/routes.py
Normal file
78
api/funkwhale_api/federation/routes.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
import logging
|
||||
|
||||
from . import activity
|
||||
from . import serializers
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
inbox = activity.InboxRouter()
|
||||
outbox = activity.OutboxRouter()
|
||||
|
||||
|
||||
def with_recipients(payload, to=[], cc=[]):
|
||||
if to:
|
||||
payload["to"] = to
|
||||
if cc:
|
||||
payload["cc"] = cc
|
||||
return payload
|
||||
|
||||
|
||||
@inbox.register({"type": "Follow"})
|
||||
def inbox_follow(payload, context):
|
||||
context["recipient"] = [
|
||||
ii.actor for ii in context["inbox_items"] if ii.type == "to"
|
||||
][0]
|
||||
serializer = serializers.FollowSerializer(data=payload, context=context)
|
||||
if not serializer.is_valid(raise_exception=context.get("raise_exception", False)):
|
||||
logger.debug(
|
||||
"Discarding invalid follow from {}: %s",
|
||||
context["actor"].fid,
|
||||
serializer.errors,
|
||||
)
|
||||
return
|
||||
|
||||
autoapprove = serializer.validated_data["object"].should_autoapprove_follow(
|
||||
context["actor"]
|
||||
)
|
||||
follow = serializer.save(approved=autoapprove)
|
||||
|
||||
if autoapprove:
|
||||
activity.accept_follow(follow)
|
||||
|
||||
|
||||
@inbox.register({"type": "Accept"})
|
||||
def inbox_accept(payload, context):
|
||||
context["recipient"] = [
|
||||
ii.actor for ii in context["inbox_items"] if ii.type == "to"
|
||||
][0]
|
||||
serializer = serializers.AcceptFollowSerializer(data=payload, context=context)
|
||||
if not serializer.is_valid(raise_exception=context.get("raise_exception", False)):
|
||||
logger.debug(
|
||||
"Discarding invalid accept from {}: %s",
|
||||
context["actor"].fid,
|
||||
serializer.errors,
|
||||
)
|
||||
return
|
||||
|
||||
serializer.save()
|
||||
|
||||
|
||||
@outbox.register({"type": "Accept"})
|
||||
def outbox_accept(context):
|
||||
follow = context["follow"]
|
||||
if follow._meta.label == "federation.LibraryFollow":
|
||||
actor = follow.target.actor
|
||||
else:
|
||||
actor = follow.target
|
||||
payload = serializers.AcceptFollowSerializer(follow, context={"actor": actor}).data
|
||||
yield {"actor": actor, "payload": with_recipients(payload, to=[follow.actor])}
|
||||
|
||||
|
||||
@outbox.register({"type": "Follow"})
|
||||
def outbox_follow(context):
|
||||
follow = context["follow"]
|
||||
if follow._meta.label == "federation.LibraryFollow":
|
||||
target = follow.target.actor
|
||||
else:
|
||||
target = follow.target
|
||||
payload = serializers.FollowSerializer(follow, context={"actor": follow.actor}).data
|
||||
yield {"actor": follow.actor, "payload": with_recipients(payload, to=[target])}
|
Loading…
Add table
Add a link
Reference in a new issue