5

I'm trying to think of the best way to structure a database to allow users to send/accept/decline users as friends.

I've currently got a system that allows users to search through users, checks all the necessary stuff like people already being on their list bhalbhla, but I don't know how to finish it off with actually sending the invites.

My structure looks like:

Users
   290384239843
      friends:
          093824098209384: true
      username: Bob
Usernames
      Bob: 290384239843

I figure when I hit the add button, it sends something to both users on Firebase, and I think the two options are:

users
  29038493
    friends
       0283940839024: pending

or

users 
  02938409384
    friends
       3094809384903 : true
    pendingFriends: 
       0283940839024: true

I think both could potentially work, but I figured I'd reach out incase I could get some guidance from someone with more experience with this. Maybe there's a better way entirely different?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
J.Doe
  • 377
  • 3
  • 15
  • Hey. I'm migrating from Parse to Firebase. Could you share how you're checking people already being on their lists and other necessary checks? I used to use Cloud-Code on Parse, not sure how to do it over on Firebase. – Zen Dec 17 '16 at 11:32
  • http://stackoverflow.com/questions/41198113/sending-friend-request-using-firebase-on-android – Zen Dec 17 '16 at 11:32

1 Answers1

3

Both your options look good to me. You have to think about where you want this information regarding "friend requests" to be displayed in your app and if you need it displayed in other ways (like see all pending friend requests or see all the friend requests a user has sent out) and duplicate the request data to all the nodes you need. You can also use, instead of status = "pending" a simple true \ false value.

True = friends 
False = not approved
Null = does not exist
Gil
  • 559
  • 6
  • 18
  • Would you be able to help me with this? http://stackoverflow.com/questions/41198113/sending-friend-request-using-firebase-on-android – Zen Dec 18 '16 at 21:51
  • 1
    Could you explain how you would now setup the rules for the db? So that a user can't just simply add him-self as a friend? – Georg Mar 03 '17 at 16:11
  • Say we have a feed of people he's not friends yet. How do you remove that person from his feed if he and that person becomes friends? – Mikebarson Sep 06 '17 at 06:34