diff --git a/calls.py b/calls.py index 7ec7f2c..f751207 100644 --- a/calls.py +++ b/calls.py @@ -58,20 +58,19 @@ def add_friend(token, friend_uid): else: friends = {} + if friend_uid in friends.values(): + return "Friend already in the list." + index = len(friends) - friend_key = f"friend{index}" - if friend_key not in friends: - friends[friend_key] = friend_uid - friends_json = json.dumps(friends) + friends[friend_key] = friend_uid + friends_json = json.dumps(friends) - cursor.execute( - "UPDATE users SET friend_list = %s WHERE session_token = %s;", - (friends_json, token) - ) - conn.commit() - else: - return False + cursor.execute( + "UPDATE users SET friend_list = %s WHERE session_token = %s;", + (friends_json, token) + ) + conn.commit() return True except Exception as e: