How to show Firebase data only once?

Viewed 126

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.

1 Answers

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