As I mentioned in the question I raised earlier this week, I'm using User Relationships to create unidirectional friendships between users on my site.
The friending paradigm is like Twitter, where Alice may follow Bob and that does not imply that Bob also follows Alice. That said, Bob is able subsequently to choose to follow Alice.
Looking in the database table user_relationships
, I can see that this situation results in two rows for a reciprocated relationship:
mysql> select * from user_relationships where requester_id in (187767, 190348)
and requestee_id in (187767, 190348);
+--------+--------------+--------------+------+----------+------------+------------+-------+
| rid | requester_id | requestee_id | rtid | approved | created | changed | flags |
+--------+--------------+--------------+------+----------+------------+------------+-------+
| 200726 | 187767 | 190348 | 1 | 1 | 1331657565 | 1331657565 | 0 |
| 200723 | 190348 | 187767 | 1 | 1 | 1331656437 | 1331656437 | 0 |
+--------+--------------+--------------+------+----------+------------+------------+-------+
2 rows in set (0.00 sec)
For ease of discussion here, let's talk about a specific View — that of "users who follow you but you don't follow back". For these users, there will be a row in user_relationship
with requestee_id
being $current_user‑>uid
, let's say this has a requester_id
of $follower‑>uid
. There will be no row, however where $current_user‑>uid
is the requester_id
and $follower‑>uid
is the requestee_id
(which would indicate that the current user had reciprocated by following back). So if we're looking at the output above, it would be the situation where only the first row (rid = 200726
) exists, from the perspective of user 190348
.
This is slightly easier to explain with a Venn diagram that I've hastily knocked-up:
; my View here is of the area labelled C
.
Now in my View (of which there is a now out-of-date screenshot), I have two Contextual Filters:
- "User relationships: Requester user", bound to the "requester" Relationship and set to Exclude; and
- "User relationships: Requestee user", bound to the "requestee" Relationship, not set to Exclude.
So far so good. Except this shows me all users who follow $current_user
, not just the ones that $current_user
does not also follow back — B ∪ C
. If I want to show only the users in C
, then I also need to check that no reverse row exists. If I go to add a new Contextual Filter, I don't have any option to check something like this (as it is not a property of the individual row I'm showing).
So how do I achieve this? I guess I'm going to have to write some PHP to prevent displaying users where this is the case and there are custom modules in my site already, but I don't understand Drupal well enough to know what hook I'm looking for or where to intercept the processing of the rows being displayed.
Help, please? :o)