Reputation: 745
I'm using FirebaseRecyclerAdapter to show posts. But I don't want to show all the posts. I just want to show posts which are posted by current user's friends. Current User's friends in Realtime Database is stored in this way:
And Every post is stored with the uid of User who posted it, in following way:
So, what will be the efficient way to retrieve posts from only current user's friends.
Upvotes: 1
Views: 2107
Reputation: 745
Solution for this issue is use FirebaseIndexRecyclerAdapter instead of FirebaseRecyclerAdapter. Link: https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#using-firebaseui-with-indexed-data
Step by Step:
First-> maintain post of every user in a node let say "My_Challenges":
So whenever a user post anything, copy that post id under user uid inside this node too.
Second-> Maintain another node for posts which you can see(in my case i want to see only my friends posts) let say "timelineIndex":
Let say User 1(1014382358695053) and User 2(10207254337991322) are friend. So copy all post id from My_Challenges of User 1 to timelineIndex of User 2 and vice versa also. (NOTE : You have to do this every time a new post id comes under your uid copy it to your friend uid under timelineIndex)
Finally-> Use FirebaseIndexRecyclerAdapter : As in above given link, use
keyRef = databaseReference.child("timelineIndex").child(mUserId);
dataRef = databaseReference.child("Blogs");
That's it. I hope it helps.
Upvotes: 2
Reputation: 190
To prevent people from seeing the posts you should use some method of authentication. This way the only people that can see the posts are the people who are logged in. Firebase one to one messaging is not directly supported as stated in this previous question:
How to send one to one message using Firebase Messaging
Upvotes: 0