Trigger rebroadcast of follow requests

This commit is contained in:
Mouse Reeve 2022-03-24 11:25:42 -07:00
parent 88e915409b
commit a3b9c621af
2 changed files with 11 additions and 12 deletions

View file

@ -133,7 +133,9 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship):
user_object=self.user_subject, user_object=self.user_subject,
) )
).exists(): ).exists():
raise IntegrityError() raise IntegrityError(
"Attempting to follow blocked user", self.user_subject, self.user_object
)
super().save(*args, **kwargs) super().save(*args, **kwargs)
if broadcast and self.user_subject.local and not self.user_object.local: if broadcast and self.user_subject.local and not self.user_object.local:

View file

@ -2,7 +2,6 @@
import urllib.parse import urllib.parse
import re import re
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.db import IntegrityError
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
@ -23,16 +22,14 @@ def follow(request):
username = request.POST["user"] username = request.POST["user"]
to_follow = get_user_from_username(request.user, username) to_follow = get_user_from_username(request.user, username)
try: follow_request, created = models.UserFollowRequest.objects.get_or_create(
models.UserFollowRequest.objects.create( user_subject=request.user,
user_subject=request.user, user_object=to_follow,
user_object=to_follow, )
) if not created:
except IntegrityError: # this request probably failed to connect with the remote
pass # that means we should save to trigger a re-broadcast
follow_request.save()
if request.GET.get("next"):
return redirect(request.GET.get("next", "/"))
return redirect(to_follow.local_path) return redirect(to_follow.local_path)