This commit is contained in:
Mouse Reeve
2021-01-26 13:00:36 -08:00
parent acfc865d4e
commit 22e4138555
7 changed files with 63 additions and 5 deletions

View File

@ -3,7 +3,6 @@ import json
from urllib.parse import urldefrag
import django.db.utils
from django.db.models import Q
from django.http import HttpResponse
from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.views.decorators.csrf import csrf_exempt
@ -64,6 +63,7 @@ def shared_inbox(request):
'Follow': handle_unfollow,
'Like': handle_unfavorite,
'Announce': handle_unboost,
'Block': handle_unblock,
},
'Update': {
'Person': handle_update_user,
@ -185,10 +185,24 @@ def handle_follow_reject(activity):
def handle_block(activity):
''' blocking a user '''
# create "block" databse entry
block = activitypub.Block(**activity).to_model(models.UserBlocks)
activitypub.Block(**activity).to_model(models.UserBlocks)
# the removing relationships is handled in post-save hook in model
@app.task
def handle_unblock(activity):
''' undoing a block '''
try:
block_id = activity['object']['id']
except KeyError:
return
try:
block = models.UserBlocks.objects.get(remote_id=block_id)
except models.UserBlocks.DoesNotExist:
return
block.delete()
@app.task
def handle_create(activity):
''' someone did something, good on them '''