The data browser is built for Chrome, Firefox, Safari, and IE9 and above. Please upgrade your browser, or download Google Chrome to get the best experience.
Back to Questions

Build friend relations into PFUser?

19 votes     4 answers     8.65k views     

19

Are there any plans to build a friend relation system into PFUser? Although this can be done 'the long way' at the moment, it requires maintaining a friend array in each user, and, more difficultly, maintaining a friend requests array for each user.

My main difficulty at the moment is trying to work out how to send a friend request. Since another users User object cannot be modified by anyone but themselves, it is not possible to add yourself to their friend request array. Am I missing something here?

4 Answers

4

Thanks for the feature request. It's always helpful to see what folks are looking for from us.

In the meantime, one option to address your scenario is to create a FriendRequest class where the requester and the requestee are both linked from the object. Then, the requestee can query for his own friend requests and optionally add them to his friend list or otherwise process the request.

I created new FriendsClass where user can save and update all the friend request/accept/deny. But I am having hard time updating the same row. Each I make changes to the status it is adding a new row to the class. Any idea how I can get around this?

- Rahul S. Khorjekar over 1 year ago
12

I second the feature request - I'd also love to see this built in. You could also do some really cool stuff with Facebook and Twitter friend data to make this really seamless.

In the mean time, here's how I'm thinking of doing this: Each user simply has their own friends array. When sending a friends request, they add the objectId of the other user to their own friends array, and send off a push notification. For the other user to accept, they in turn add the objectId of the first user to their friends array. To find all accepted (mutual) friendships, you query for users where their objectId is contained in your friends array, and also where your objectId is contained within their friends array:

[query whereKey:@"objectId" containedIn:[[PFUser currentUser] objectForKey:@"friends"]];
[query whereKey:@"friends" equalTo:[PFUser currentUser].objectId];
[query whereKey:@"objectId" notEqualTo:[PFUser currentUser].objectId];

To find "pending" friend requests, simply query for users with the current user in their friends array who are not also in the current user's friends array.

To handle situations where a user declines a friend request, I'm planning on also having a "blocks" array on each user.

I feel like this might be a simpler and cleaner solution than having a separate FriendRequest class. Although it might not be so flexible, for example if you wanted to include a message with the request.

I'd love to hear other people's ideas too if they have any.

I'm trying to do the same in a similar way to Matt here. However I'm having trouble working out how to get pending (incoming) friend requests for the current user.

I'm storing friends as a Parse.Relation field on User ie user.relation('requestedFriends')

I can get a collection of inward friend requests like this: <code>

    var query = new Parse.Query(MyApp.Friend);
    query.equalTo('requestedFriends', currentUser);

</code> But I can't work out how to filter out the friends who are in the currentUser.relation('requestedFriends') relation list. I've tried using doesNotMatchQuery, notEqualTo, notContainedIn.

Some guidance on solving this would be much appreciated! t.y.

- Meirion over 1 year ago

No formatting options for these comments?! nnngh doh. Might be forced to post it as an answer...

- Meirion over 1 year ago
4

I think it would not be a good idea to build an inherent friend feature in a PFUser object. An api is supposed to be generic and outside of social (or games etc), it would be hard to justify it.

Though a built-in subclass of PFUser, say PFFriendlyUser, :), may be good. And PFFriendlyUser could have extensive support for social networks features.

-4

I created new FriendsClass where user can save and update all the friend request/accept/deny. But I am having hard time updating the same row. Each I make changes to the status it is adding a new row to the class. Any idea how I can get around this?