From 9d8f4613d4c29d76eeec3523dd88d25c98161989 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Mon, 28 Sep 2020 17:08:15 +0100 Subject: [PATCH] When trilby_api hears about a follow request, and the person being followed has "auto_follow" turned on, the request is automatically granted. If the follower is remote, they automatically get sent an Accept activity. This fixes a regression. As part of this, bowler_pub.create() now sends the ID of the Follow activity through the signal. Also, trilby_api.receivers now uses sensible renames for the "sender" parameters-- they're really the activities which caused the signal. --- kepi/bowler_pub/create.py | 5 ++++- kepi/trilby_api/receivers.py | 39 +++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/kepi/bowler_pub/create.py b/kepi/bowler_pub/create.py index 732c272..9564c0b 100644 --- a/kepi/bowler_pub/create.py +++ b/kepi/bowler_pub/create.py @@ -97,7 +97,10 @@ def on_follow(message): result.save() - trilby_signals.followed.send(sender = result) + trilby_signals.followed.send( + sender = result, + id = fields.get('id'), + ) return result diff --git a/kepi/trilby_api/receivers.py b/kepi/trilby_api/receivers.py index 2bc9928..22ceb82 100644 --- a/kepi/trilby_api/receivers.py +++ b/kepi/trilby_api/receivers.py @@ -9,6 +9,7 @@ logger = logging.getLogger(name='kepi') import kepi.trilby_api.signals as kepi_signals import kepi.trilby_api.models as kepi_models +import kepi.sombrero_sendpub.delivery as sombrero_delivery from django.dispatch import receiver ################################################## @@ -19,10 +20,12 @@ from django.dispatch import receiver @receiver(kepi_signals.followed) def on_follow(sender, **kwargs): + follow = sender # rename to prevent confusion below + notification = kepi_models.Notification( notification_type = kepi_models.Notification.FOLLOW, - for_account = sender.following, - about_account = sender.follower, + for_account = follow.following, + about_account = follow.follower, ) notification.save() @@ -30,14 +33,40 @@ def on_follow(sender, **kwargs): logger.info(' -- storing a notification: %s', notification) + if follow.following.auto_follow: + logger.info(" -- sending automatic Accept") + + if isinstance(follow.follower, kepi_models.RemotePerson): + accept = { + 'type': 'Accept', + 'to': [follow.follower.url], + 'actor': follow.following.url, + 'object': kwargs.get('id'), + } + + sombrero_delivery.deliver( + activity = accept, + sender = follow.following, + target_people = [ + follow.follower, + ], + ) + + follow.requested = False + follow.save() + else: + logger.info(" -- not sending automatic Accept") + @receiver(kepi_signals.liked) def on_like(sender, **kwargs): + like = sender # rename to prevent confusion below + notification = kepi_models.Notification( notification_type = kepi_models.Notification.FAVOURITE, - for_account = sender.liked.account, - about_account = sender.liker, - status = sender.liked, + for_account = like.liked.account, + about_account = like.liker, + status = like.liked, ) notification.save()