mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-26 17:08:09 +00:00
Send accepts to duplicate follow requests
This commit is contained in:
parent
d5b27e2202
commit
6b84e53ddd
1 changed files with 10 additions and 4 deletions
|
@ -101,12 +101,15 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship):
|
||||||
|
|
||||||
def save(self, *args, broadcast=True, **kwargs):
|
def save(self, *args, broadcast=True, **kwargs):
|
||||||
""" make sure the follow or block relationship doesn't already exist """
|
""" make sure the follow or block relationship doesn't already exist """
|
||||||
# don't create a request if a follow already exists
|
# if there's a request for a follow that already exists, accept it
|
||||||
|
# without changing the local database state
|
||||||
if UserFollows.objects.filter(
|
if UserFollows.objects.filter(
|
||||||
user_subject=self.user_subject,
|
user_subject=self.user_subject,
|
||||||
user_object=self.user_object,
|
user_object=self.user_object,
|
||||||
).exists():
|
).exists():
|
||||||
raise IntegrityError()
|
self.accept(broadcast_only=True)
|
||||||
|
return
|
||||||
|
|
||||||
# blocking in either direction is a no-go
|
# blocking in either direction is a no-go
|
||||||
if UserBlocks.objects.filter(
|
if UserBlocks.objects.filter(
|
||||||
Q(
|
Q(
|
||||||
|
@ -141,9 +144,9 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship):
|
||||||
""" get id for sending an accept or reject of a local user """
|
""" get id for sending an accept or reject of a local user """
|
||||||
|
|
||||||
base_path = self.user_object.remote_id
|
base_path = self.user_object.remote_id
|
||||||
return "%s#%s/%d" % (base_path, status, self.id)
|
return "%s#%s/%d" % (base_path, status, self.id or 0)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self, broadcast_only=False):
|
||||||
""" turn this request into the real deal"""
|
""" turn this request into the real deal"""
|
||||||
user = self.user_object
|
user = self.user_object
|
||||||
if not self.user_subject.local:
|
if not self.user_subject.local:
|
||||||
|
@ -153,6 +156,9 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship):
|
||||||
object=self.to_activity(),
|
object=self.to_activity(),
|
||||||
).serialize()
|
).serialize()
|
||||||
self.broadcast(activity, user)
|
self.broadcast(activity, user)
|
||||||
|
if broadcast_only:
|
||||||
|
return
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
UserFollows.from_request(self)
|
UserFollows.from_request(self)
|
||||||
self.delete()
|
self.delete()
|
||||||
|
|
Loading…
Reference in a new issue