def send_friend_request(id): id = int(id) if current_user.id == id: return 'error' receiver_settings = UserSettings.query.filter_by(user=id).first() if receiver_settings and not receiver_settings.allow_friend_requests: return jsonify('error') friendship = Friendship.query \ .filter(((Friendship.user1_id == id) & (Friendship.user2_id == current_user.id)) | ((Friendship.user2_id == id) & (Friendship.user1_id == current_user.id))).first() if not friendship: friendship_request = FriendshipRequest.query \ .filter(((FriendshipRequest.requesting_user_id == id) & (FriendshipRequest.receiving_user_id == current_user.id)) | ((FriendshipRequest.receiving_user_id == id) & (FriendshipRequest.requesting_user_id == current_user.id))).first() if not friendship_request: friendship_request = FriendshipRequest( requesting_user_id=current_user.id, receiving_user_id=id) db.session.add(friendship_request) db.session.commit() return jsonify('success')
def send_friend_request(id): id = int(id) if current_user.id == id: return 'error' friendship = Friendship.query \ .filter(((Friendship.user1_id == id) & (Friendship.user2_id == current_user.id)) | ((Friendship.user2_id == id) & (Friendship.user1_id == current_user.id))).first() if not friendship: friendship_request = FriendshipRequest.query \ .filter(((FriendshipRequest.requesting_user_id == id) & (FriendshipRequest.receiving_user_id == current_user.id)) | ((FriendshipRequest.receiving_user_id == id) & (FriendshipRequest.requesting_user_id == current_user.id))).first() if not friendship_request: friendship_request = FriendshipRequest( requesting_user_id=current_user.id, receiving_user_id=id) db.session.add(friendship_request) db.session.commit() return jsonify('success')