You're looking at our questions archive. This question was last updated about 2 years ago.
If you're looking for help, head over to the Parse Developers Google Group or check out the parse.com tag on Stack Overflow.Help Google Group Stack Overflow
25 votes 4 answers 14.4k views about 2 years ago
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?
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 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 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.
Rahul S. Khorjekar
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?