Don't create duplicate boosts.

This commit is contained in:
Adam Kelly 2020-03-30 16:39:53 +01:00
parent acffb36f46
commit a4c257a8d2

View file

@ -293,16 +293,15 @@ def handle_unfavorite(user, status):
def handle_boost(user, status): def handle_boost(user, status):
''' a user wishes to boost a status ''' ''' a user wishes to boost a status '''
try: if models.Boost.objects.filter(
boost = models.Boost.objects.create( boosted_status=status, user=user).exists():
boosted_status=status, # you already boosted that.
user=user,
)
boost.save()
except IntegrityError:
# you already boosted that
# TODO - doesn't work because unique constraint isn't enforcable.
return return
boost = models.Boost.objects.create(
boosted_status=status,
user=user,
)
boost.save()
boost_activity = activitypub.get_boost(boost) boost_activity = activitypub.get_boost(boost)
recipients = get_recipients(user, 'public') recipients = get_recipients(user, 'public')