django-friendship icon indicating copy to clipboard operation
django-friendship copied to clipboard

Enhancement: Add util method within FriendshipManager to check if friend request is sent

Open Azeddev28 opened this issue 6 months ago • 3 comments

Within FrienshipManager, there are two checks: https://github.com/revsys/django-friendship/blob/593d63b7214a9c1d6662aadd0b50642947192c98/friendship/models.py#L290-L298

These validate if a request is sent from a from_user or a to_user. These can be converted into a util method to be used from the FrienshipManager rather than copying these two checks outside of the manager if needed.

I have the util method defined like this

  def check_if_request_sent(self, from_user, to_user):
        if FriendshipRequest.objects.filter(
            from_user=from_user, to_user=to_user
        ).exists():
            raise AlreadyExistsError("You already requested friendship from this user.")

        if FriendshipRequest.objects.filter(
            from_user=to_user, to_user=from_user
        ).exists():
            raise AlreadyExistsError("This user already requested friendship from you.")

Can open a PR, once the idea is approved

Azeddev28 avatar Aug 26 '24 08:08 Azeddev28