Properly send webmentions after deleting an entry :3

This commit is contained in:
Danielle McLean 2018-07-02 15:30:32 +10:00
parent fa8419976d
commit bab7097fa3
Signed by untrusted user: 00dani
GPG key ID: 8EB789DDF3ABD240
2 changed files with 13 additions and 6 deletions

View file

@ -14,9 +14,10 @@ def ping_hub(*urls):
@job @job
def send_mentions(source): def send_mentions(source, targets=None):
result = webmention.findMentions(source) if targets is None:
for target in result['refs']: targets = webmention.findMentions(source)['refs']
for target in targets:
status, endpoint = webmention.discoverEndpoint(target) status, endpoint = webmention.discoverEndpoint(target)
if endpoint is not None and status == 200: if endpoint is not None and status == 200:
webmention.sendWebmention(source, target, endpoint) webmention.sendWebmention(source, target, endpoint)

View file

@ -1,8 +1,9 @@
from django.http import HttpResponse from django.http import HttpResponse
from django.urls import resolve, Resolver404 from django.urls import resolve, Resolver404
from urllib.parse import urlparse from urllib.parse import urlparse
from ronkyuu import webmention
from entries.jobs import ping_hub from entries.jobs import ping_hub, send_mentions
from entries.models import Entry from entries.models import Entry
from . import error from . import error
@ -42,7 +43,12 @@ def delete(request):
if entry.author != request.token.user: if entry.author != request.token.user:
return error.forbid('entry belongs to another user') return error.forbid('entry belongs to another user')
urls = entry.affected_urls perma = entry.absolute_url
pings = entry.affected_urls
mentions = webmention.findMentions(perma)['refs']
entry.delete() entry.delete()
ping_hub.delay(urls)
ping_hub.delay(*pings)
send_mentions.delay(perma, mentions)
return HttpResponse(status=204) return HttpResponse(status=204)