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.
status-serialisers
Marnanel Thurman 2020-09-28 17:08:15 +01:00
rodzic 3a1a5f6db2
commit 9d8f4613d4
2 zmienionych plików z 38 dodań i 6 usunięć

Wyświetl plik

@ -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

Wyświetl plik

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