1

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:

enter image description here

And Every post is stored with the uid of User who posted it, in following way:

enter image description here

So, what will be the efficient way to retrieve posts from only current user's friends.

AL.
  • 36,815
  • 10
  • 142
  • 281
Rishabh Chandel
  • 725
  • 1
  • 11
  • 28

2 Answers2

2

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": enter image description here

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": enter image description here

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.

Rishabh Chandel
  • 725
  • 1
  • 11
  • 28
0

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

Community
  • 1
  • 1
JordanH
  • 190
  • 5
  • Every user is allowed to use app only after authentication. How can i restrict them from seeing only friend's post. – Rishabh Chandel Feb 13 '17 at 16:56
  • I am talking about additional authentication other than the Gmail login, such as a username and password that are individual to the server. – JordanH Feb 13 '17 at 20:40
  • I think you are not getting me. I'm talking somewhat about facebook, if any of my friend posting something, it should come to my timeline. Infact it should come to every of its friend's timeline. And say if you post something and you are not my friend, i won't get your post in my timeline. It's like facebook. – Rishabh Chandel Feb 14 '17 at 18:44
  • Yes and what I am saying is that this is not a native feature of firebase so you would need to set up your own authentication that accounts for the different users. – JordanH Feb 14 '17 at 23:22