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
Related
Disclaimer: I have never worked with firebase or any other DB so my idea is pretty rough and I will be glad if u correct me in some of my assumptions. Also this is my first question on StackOverflow so I hope it will be detailed enough.
I am currently working on my project which is basically a group chat in flutter using firebase, where I should be able to create a new group chat(create a new DB in firestore) trough the app, let other ppl join(assign them to the new group chat DB).
The twist: If I send a message to the group chat I want other ppl to see a pop-up saying: "do you accept this message", no=> doesn't show / yes=> Shows the message but deletes it for others.
This app is nothing but my idea of how to confirm my theory and also learn a little bit more about both flutter and firebase, so please do not mind if it's useful or not.
Assumption: Each groupchat has it's own DB (Can I create a DB in firestore trough app / send request to?)
Question: Can I assign a specific ID to each message and choose and further edit who is going to be able to see the message trough the app(app_instance_1"I accepted the message so only I and sender can see it")?
Here's a great article for making a Flutter chat app: https://medium.com/flutter-community/building-chat-app-in-flutter-with-firebase-888b6222fe20. If you need more detail or help just write a comment.
About your assumption. Each app usually is connected to one database, and within the database, you can have separate documents to hold each group chat. You can also set up documents for each individual user to save the chats that only they can see. Within documents, you add collections that hold your data.
I have a simple Firebase database:
I would like to create an Android app where everybody can posts short texts. However, on the main screen I would like to show only those posts from other users who I followed. On the example, this means that if I logged in like Mrs. Nobody into the app, I can see only the first post created by Mr. Nobody.
Is that possible? (I tried to receive every posts in "posts" and after that I could show only posts what are relevant for me, but data traffic was really high in this case)
I have another idea, but I try to find a more efficient one. My idea is to receive every relations from "relations" where follow_uid is mine. After that, I iterate through all the elements and I download those posts where uid is equals with the uid from "relations"
I recently started to learn Android and I came across a problem. I want to create a code for Firebase (the database I am using to store values) such that the contents from one set are matched to elements in another set.
The scenario is as follows: there is a student who wants to learn or is interested in learning a new skill (C/C++, drawing, music, etc.), if he were to update them in their profile, he should get suggestions as names of other users registered in the application who have already listed their skill set.
It is much like how Facebook suggests common friends, but here, the basis for suggestion is what skills the user has and what he wants to learn.
I worked on the same thing for one of my apps. I'll write about what I did to achieve that
First of all, you need to design your Realtime Database structure in a way to achieve that.
Example of a Individual User node in your database at firebase could be like
User
- Personal Details
- First name
- last name
- Dob
- Interests (values like "music,movies,sports") //Separated by a comma
- ...
Now lets say User A likes "music" and that you need to suggest him other users who likes music too, In this case what you can do is retrieve all the users who have interests "music" in their profile.
reference.addChildEventListener()
In here,inside the onChildAdded() you can compare to see if the Interest of a particular user has music in it. (if it does, add that user to your arraylist for your recyclerview to display it.)
Hope it helps!
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 am trying to create a 'like' feature for my android app using parse as backend.I am currently giving the user the option to like or dislike a post in the details screen. But I want to give the user the option to like a post in the feeds section instead of opening the details screen like tumblr,facebook,twitter and many other apps.I know one way of doing it is running a inner query for every post to check if the post is liked or not.But suppose I am loading 25 posts for the feeds section then I will need to run inner queries for the 25 posts at the same time which will cause performance overhead.So is there any other optimized way for doing.How is the anypic and other parse apps doing this? Please help.
Add a property to your Post class called LikedBy which is an array of pointers to users.
Whenever a user likes the post, add them to the array. Then when you query for the posts, use includeKey on the array and you will know who and how many people have liked it :)