Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix relationship migration #367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ def migrate_relationships(apps, schema_editor):
APIdentity = apps.get_model("users", "APIdentity")
logger.info(f"Migrate user relationship")
for user in tqdm(User.objects.all()):
for target in user.local_following:
for target in user.local_following.all():
user.identity.follow(User.objects.get(pk=target).identity)
for target in user.local_blocking:
for target in user.local_blocking.all():
user.identity.block(User.objects.get(pk=target).identity)
for target in user.local_muting:
for target in user.local_muting.all():
user.identity.block(User.objects.get(pk=target).identity)
user.sync_relationship()
for user in tqdm(User.objects.all()):
for req in user.identity.following_request:
target_identity = APIdentity.objects.get(pk=req)
for target_identity in user.identity.follow_requesting_identities:
target_identity.accept_follow_request(user.identity)


Expand Down
6 changes: 3 additions & 3 deletions users/models/apidentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def requested_follower_identities(self):

@property
def follow_requesting_identities(self):
return APIdentity.objects.filter(pk__in=self.following_request)
return APIdentity.objects.filter(pk__in=self.following_requests)

@property
def rejecting(self):
Expand All @@ -165,7 +165,7 @@ def requested_followers(self):
return Takahe.get_requested_follower_ids(self.pk)

@property
def following_request(self):
def following_requests(self):
return Takahe.get_following_request_ids(self.pk)

def accept_follow_request(self, target: "APIdentity"):
Expand Down Expand Up @@ -204,7 +204,7 @@ def is_following(self, target: "APIdentity"):
return target.pk in self.following

def is_requesting(self, target: "APIdentity"):
return target.pk in self.following_request
return target.pk in self.following_requests

def is_requested(self, target: "APIdentity"):
return target.pk in self.requested_followers
Expand Down