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.
Related
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 have a Firebase database with a list of users and a list of best friends,
a user's best friends can be pulled by using it's userid:
users list:
userid
user data
userid
user data
..
best friends list:
userid
userid of friend
userid of friend
...
userid
userid of friend
userid of friend
...
...
...
Is there a way using the Firebase api to get the friend's data in a list instead of a list of userid's of your friends when making the call to get your best friends ? Now i have to do 2 steps (get best friends id's -> loop users for friend's data)
No, there is not. There is no way to achieve this. You need to query your data twice, first time to get best friends id's and second to get the actual data of those friends. You cannot get that list in a single step, using a single query..
What I think from your description is that you want to perform a join.
There's no official "join" method in the Firebase Database SDK, but
you can use multiple listeners to combine data from multiple paths.
https://www.youtube.com/watch?v=Idu9EJPSxiY
check out this youtube video it will help
I am creating an application that would allow users to access data on their phones. Examples would be progress scores/test results.
I can upload the data to Firebase with an email address as the user link.
Is there a way that I can link this already loaded data to a user (with the same email address) once they have registered? Ideally using the email address in a rule to search up that data and use that reference point in the app.
Ideally I would like to pre-upload the users in bulk, but I know that Firebase only allows one user to be added at a time.
Any help would be appreciated.
After a user sign in to the app through the Firebase auth you can get its email through this call:
FirebaseAuth.getInstance().getCurrentUser().getEmail()
If you want to import data into your database, you should first make a json out of your data (list of users by email) and then use Firebase-Import to put it in your datastore.
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
We associate every parse user to their facebook ID as in the documentation.
ParseFacebookUtils.link(user, this, new SaveCallback()
However how is it possible to query the objects of a facebook friend using his facebook ID in Parse SDK Android?
This is only possible if you store the relationship information in Parse by associating the information with the user record. Even though Parse stores the facebook ID in the authData column, it is not queryable there.
You can get the facebook ID from the Graph API after user logs in (link) and store it as an additional column on the user record in Parse. When the user adds a friend, store this relationship in a table of your making. You can query that table to determine what the friend IDs are and access the appropriate data.
Alternately, if these queries only need to run while the user is currently logged in, you don't have to store the friend relationships. You can query the graph API (/me/friends) to get a list of friends of the user that are using your app. Facebook guarantees that they will return the same user IDs to your app each time.