1
0
Fork 0

Don't fav things multiple times

Fixes #28
This commit is contained in:
Mouse Reeve 2020-02-19 00:22:55 -08:00
parent a664ad3328
commit 77841909fe
4 changed files with 21 additions and 6 deletions

View file

@ -1,4 +1,5 @@
''' handles all the activity coming out of the server '''
from django.db import IntegrityError
from django.http import HttpResponseNotFound, JsonResponse
from django.views.decorators.csrf import csrf_exempt
import requests
@ -172,10 +173,15 @@ def handle_comment(user, review, content):
def handle_outgoing_favorite(user, status):
''' a user likes a status '''
favorite = models.Favorite.objects.create(
status=status,
user=user
)
try:
favorite = models.Favorite.objects.create(
status=status,
user=user
)
except IntegrityError:
# you already fav'ed that
return
fav_activity = activitypub.get_favorite(favorite)
recipients = get_recipients(user, 'direct', [status.user])
broadcast(user, fav_activity, recipients)