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()