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.
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.
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
Related
I'm working on an android app which uses Firebase Realtime database.
This app is quite similar like a social media app with limited functionality.
The app will show the post contain text data to the users.
I'm stuck with the two problem in which I solved the first one with the help of Pagination but couldn't able to solve the second .
The problem is How can I identify if the post is already seen by the other users and then not show it again.
like other social media platforms
For example Quora, Quora will show different answer every time we open the app.
Do I need to remap my data get this functionality ?
My user object and post object will look something like this.
User{
Name;
Id;
Post;
}
Post {
dateCreated;
data;
userId;
}
My database tree structure will look something like this
ROOT
/ \
POST Users
I'm keeping the copy of the post in child node of ROOT that is POST and also in every users node to get the post posted by the user.
PS: sorry for the poor English.
If you want to
1- Show posts with NO views yet, you can filter posts where for example num_reads < 3. The num_reads will be increased everytime a user sees the post.
2- Show posts to use which the user himself didn't read yet. In this case it is better to create a collection user_post_read which will be many-to-many (ie. link user to post read). Get all posts where the is no entry for current user in user_post_read
I have done phone authentication linked to my project but I am not pushing the data from android instead I have manually entered the user data in Firebase. And I want to retrieve the data from firebase using OTP verification and I just need to search the specific user data with phone number which I am entering while login. I want to show all fields to be displayed which are present in my firebase database into my android project.
I've tried many methods to receive the data but I am stuck... Please help me.
Database structure
Authentication panal
You need to logically bind your authenticated user and the data that you stored in your firebase. As per the image in your data base 'id' of the 'Users' are 1,2,.. like that. Instead of that you can use 'UID' of users as an an Id in your database. Go to your 'Authentication' section, you will see User UID against each registered user. Copy that and use as an ID while creating data in database. This will help you to get the data with reference like Users\. Hope this will solve your problem.
I am developing a Firebase chat app.
I have implemented Firebase email/password authentication. So, when user signups successfully, I have a code through which on every signup/register the app stores user details like name,email, etc in Firebase database under uid node.
Then, the user searches for a friend using a email id,
if the uid with that email id is present in the firebase database, the function returns true,
then, the app, adds that email id under
<FirebaseApp>
<users>
....users details...
<friends>
<userid>
<unique pushed id> : searched email // here the friend's email id is added
After adding the new friend,
I am using a recyclerview to show the friend list.
So, the app retrieves all the nodes under friends>> current user's uid>>
As my database structure describes I have only saved friends uid in friends database.
At first step the user will have only friends' email ids. Let say in List friendsList.
Then I use this friendsList to retrieve all the other details of friends like profile picture, name, contact and etc... which is saved under users node.
But using for each loop retrieving the other details of every friend, and then store in a array list, then paasing that arrayList to adapter and then displaying to recyclerview. is a very time consuming process.
Becuase, it can have other functions too. like converting Base64 image to bitmap etc.
So every time activity starts , following all above steps, will make a lengthy process.
other that this, I have another way, where I can save friends other's details too under friends node. like name, contact etc. at a point when a new friend added to the database.
But again another question arises.
yes, I can store friend's other details too... But what if the friend updates his profile picture, contact?
So, this procedure is not suitable in my case.
How can I create a whatsapp like friends list in my Firebase app, where I every user's friends list will be always updated with his/her friends details.
also, the will not go under any lengthy process.
The best approach is to save all the necessary details in the friends node as well.
You can just save the Opposite_Friends tag in each user, where just add all the uids in whose friends list user is present, So that whenever user updates any detail, you can update it in every users Friends node as well.
I am building a social app, I have a database on firebase that is structured like this:
tJWRbfqUUbSQn5eI8ZS5vPG9znr1
bio:
coverPhotoUrl:
email:
firstname:
imgUrl:
lastname:
name:
phone:
posts
-KPN0b7QmNp8AjYy4yFl
-KPXmtvZdiQ--QjZ-j3m
-KPc7PpDkmFNU9JjlIJP
-KPc7PptOulQdrpsrGEp
-KPc7Pq6JC7bjt8-sRFU
-KPc7PqJ2651EIQWXIv6
the top level key is th user id, so i have that for every user, each user has posts too, inside the posts node, i have comments, pushed in the exact the same way as posts.
My question is that I am a bit curious about how i am going to model a Newsfeed, right now A Newsfeed to me is a list of posts from you and your everyone you are following in the exact order of the time they were posted while a timeline is just posts from the said user in that order too.
I have correctly done the timeline by just iterating over posts from the user
I have tried to do the Newsfeed part in two ways, which has bugs and I think is not very efficient
Since every user maintains a list of his followers in his own node, i made it such that anytime a user makes a post, he not only writes in his own 'posts node' but also in every other person following him's 'Newsfeed' node
Cons of this method
a. in the event of an unfollow, i am not able to remove user A's posts from User B's timeline
b. i am giving every user access to write in every other person's node, which as i have read, is not a very good practice.
Maintain the url of User A's post node in user B's Timeline node, which would solve the con B of method 1.
Cons of this method
a. I dont know how to implement it.
I dont know if there is any textbook way to do this(of course there has to be, there is only so much social network platforms out there), if there is i want to know, also if you could point me to how(not help me to) implement my method 2, i will very much appreciate it.
Also, i was following this similar question
which does not completely answer my question but looks like a very interesting approach
I think the solution you are looking for is referred to as client-side fan-out. This Firebase Blog post provides a great explanation and will point you in the right direction.
Client-side fan-out for data consistency
It looks like you need a new datastructure for keeping score who is following who. Use that information to build your newsfeed. That way there is no need for one user to write "into" another user. Every posting is only stored once for the user why created the post. If the follow and unfollow changes, you can simply recalculate on the fly which posts to include in a newsfeed
I want to display my facebook online friends and offline friends suppurate.But i don't know how to display.But I am getting all my facebook friends into list in my application.
Any one please help me.....How to display online and offline friends suppurate.
First - use the fb api. get the friends.
Second - show the list in beautiful Ui component or what ever.
So I understand that you have done the first, right?
If so, then what stops you to make some container and push back dynamically to it labels for example. After this you can try some more beautiful solution how I sad..
try explain more what you've done... Be more specific, please. :)
EDIT 1
Here you are: https://developers.facebook.com/docs/reference/fql/user
Use that:
online_presence
The user's Facebook Chat status. Returns a string, one of active,
idle, offline, or error (when Facebook can't determine presence
information on the server side). The query does not return the user's
Facebook Chat status when that information is restricted for privacy
reasons
EDIT 2
May be you need a loop all your friends and for each of them execute the query
SELECT online_presence FROM user WHERE username = the_friend_from_list
This is a pseudocode but I'm sure you can handle it. :)