Skip to:

“Bug” in adding friends: Multiple Friend Requests from Same Person

  • sx1001


    Hi all,

    I have a rare, but still occuring case that sometimes two persons in my BP network have multiple friendship rows in the DB, both more or less entered at the same second.

    I’m not entirely sure how to reproduce this. Probably some JS problem, or maybe a partially loaded page and reclicking the button. Anyway, JS error caused the Add Friend button to not be greyed out and each request sent using the button showed up as a dupe friend request.

    Interesting thing is: They cannot confirm their friendship, because – I mean they can confirm the first entry. But the second entry will still show is_confirmed=0 and cannot be confirmed anymore because BP_Friends_Friendship::accept() only updates the row which is already is_confirmed=1, but the other row with is_confirmed=0 still shows the pending friendship request.

    To fix this for future friendships, I was wondering why not just entering a UNIQUE index over those fields?
    UNIQUE(initiator_user_id, friend_user_id, is_confirmed)

    This would be a constrait, which would help in case somehow the AJAX to insert a friendship row gets triggered twice.

    What do you think?

Viewing 2 replies - 1 through 2 (of 2 total)

  • sx1001


    Funny, just as I posted, I saw this on github:

    But this was created only concerning the REST API.
    This happens also directly in the frontend… We have this situation every week once or so … 🙁



    Basically to fix this issue if the JS does not work properly, do a check in the Ajax call itself:

    Modify the friend add AJAX call, and add the condition:

    $res = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $_POST['item_id']);
    if(!in_array($res, array(false, 'not_friends'))) 
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar