When trying to add a friend which has already been added as a friend by another user (and that request was approved), then my request does not show up in the "Awaiting friend approvals" list.

I tracked down the problem to the join in the view, between flag_friend and the users table. It misses a condition to limit the flag_friends to the user who requests the friendship (flag_friend.uid).

SELECT DISTINCT(users.uid) AS uid,
   users.picture AS users_picture,
   users.name AS users_name,
   users.mail AS users_mail,
   flag_content_users__flag_friend_message.message AS flag_content_users__flag_friend_message_message,
   flag_content.content_id AS flag_content_content_id
 FROM users users 
 INNER JOIN flag_content flag_content_users ON users.uid = flag_content_users.content_id AND flag_content_users.fid = 4
 LEFT JOIN flag_friend flag_friend_users ON users.uid = flag_friend_users.friend_uid AND flag_friend_users.fid = 4
 LEFT JOIN flag_friend_message flag_content_users__flag_friend_message ON flag_content_users.fcid = flag_content_users__flag_friend_message.fcid
 LEFT JOIN flag_content flag_content ON users.uid = flag_content.content_id AND (flag_content.fid = 4 AND flag_content.uid = 84 AND flag_content.sid = 0)
 WHERE (users.status <> 0) AND (flag_friend_users.fid IS NULL) AND (flag_content_users.uid = 84)
 GROUP BY uid

should have an additional condition on the first LEFT JOIN, matching the flag_friend.uid with the argument provided to the view:

SELECT DISTINCT(users.uid) AS uid,
   users.picture AS users_picture,
   users.name AS users_name,
   users.mail AS users_mail,
   flag_content_users__flag_friend_message.message AS flag_content_users__flag_friend_message_message,
   flag_content.content_id AS flag_content_content_id
 FROM users users 
 INNER JOIN flag_content flag_content_users ON users.uid = flag_content_users.content_id AND flag_content_users.fid = 4
 LEFT JOIN flag_friend flag_friend_users ON users.uid = flag_friend_users.friend_uid AND flag_friend_users.fid = 4 AND flag_friend_users.uid=84
 LEFT JOIN flag_friend_message flag_content_users__flag_friend_message ON flag_content_users.fcid = flag_content_users__flag_friend_message.fcid
 LEFT JOIN flag_content flag_content ON users.uid = flag_content.content_id AND (flag_content.fid = 4 AND flag_content.uid = 84 AND flag_content.sid = 0)
 WHERE (users.status <> 0) AND (flag_friend_users.fid IS NULL) AND (flag_content_users.uid = 84)
 GROUP BY uid

Without this condition, the flag_friend entries of other requesters are joined, so it will seem like the request was approved already.

I expect the "Friend requests" page to have a similar issue, but I did not yet track down the exact changes required to make it work correctly.

Comments

cyberwolf’s picture

As a temporary fix, I now alter the query by implementing hook_views_query_alter() in my own module:

function mymodule_views_query_alter(&$view, &$query) {
  if ($view->name == 'friends') {
    switch ($view->current_display) {
      case 'page_3':
      case 'page_2':
        $query->table_queue['flag_friend_users']['join']->extra[] = array('field' => 'uid', 'value' => $view->args[0], 'numeric' => TRUE);
        break;
      }
  }
}
joecanti’s picture

Getting the same issue here i think - although I just cannot add more than one friend to any user.

Subscribing,

Joe

braindrift’s picture

Same here,

the snippet from #1 fixes this issue (also the issue from #2).

dreamdust’s picture

I can confirm the snippet from #1 fixes the issue.

sirkitree’s picture

Status: Active » Needs review

The 6.x-2.x-dev version of this module is pretty abandoned. Is this report valid for the 1.x version (which isn't abandoned)?

sirkitree’s picture

Status: Needs review » Postponed (maintainer needs more info)

wrong status

sirkitree’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Closing due to inactivity.