User serializer to create follow request
This commit is contained in:
parent
76ce20a5e0
commit
e99394e6f7
|
@ -115,26 +115,10 @@ def has_valid_signature(request, activity):
|
||||||
@app.task
|
@app.task
|
||||||
def handle_follow(activity):
|
def handle_follow(activity):
|
||||||
''' someone wants to follow a local user '''
|
''' someone wants to follow a local user '''
|
||||||
# figure out who they want to follow -- not using get_or_create because
|
|
||||||
# we only care if you want to follow local users
|
|
||||||
try:
|
try:
|
||||||
to_follow = models.User.objects.get(remote_id=activity['object'])
|
relationship = activitypub.Follow(
|
||||||
except models.User.DoesNotExist:
|
**activity
|
||||||
# some rando, who cares
|
).to_model(models.UserFollowRequest)
|
||||||
return
|
|
||||||
if not to_follow.local:
|
|
||||||
# just ignore follow alerts about other servers. maybe they should be
|
|
||||||
# handled. maybe they shouldn't be sent at all.
|
|
||||||
return
|
|
||||||
|
|
||||||
# figure out who the actor is
|
|
||||||
actor = activitypub.resolve_remote_id(models.User, activity['actor'])
|
|
||||||
try:
|
|
||||||
relationship = models.UserFollowRequest.objects.create(
|
|
||||||
user_subject=actor,
|
|
||||||
user_object=to_follow,
|
|
||||||
remote_id=activity['id']
|
|
||||||
)
|
|
||||||
except django.db.utils.IntegrityError as err:
|
except django.db.utils.IntegrityError as err:
|
||||||
if err.__cause__.diag.constraint_name != 'userfollowrequest_unique':
|
if err.__cause__.diag.constraint_name != 'userfollowrequest_unique':
|
||||||
raise
|
raise
|
||||||
|
@ -143,20 +127,15 @@ def handle_follow(activity):
|
||||||
)
|
)
|
||||||
# send the accept normally for a duplicate request
|
# send the accept normally for a duplicate request
|
||||||
|
|
||||||
if not to_follow.manually_approves_followers:
|
manually_approves = relationship.user_object.manually_approves_followers
|
||||||
status_builder.create_notification(
|
|
||||||
to_follow,
|
status_builder.create_notification(
|
||||||
'FOLLOW',
|
relationship.user_object,
|
||||||
related_user=actor
|
'FOLLOW_REQUEST' if manually_approves else 'FOLLOW',
|
||||||
)
|
related_user=relationship.user_subject
|
||||||
|
)
|
||||||
|
if not manually_approves:
|
||||||
outgoing.handle_accept(relationship)
|
outgoing.handle_accept(relationship)
|
||||||
else:
|
|
||||||
# Accept will be triggered manually
|
|
||||||
status_builder.create_notification(
|
|
||||||
to_follow,
|
|
||||||
'FOLLOW_REQUEST',
|
|
||||||
related_user=actor
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
|
|
Loading…
Reference in New Issue