简体   繁体   中英

How can I implement a "seen" feature using firebase for different users

The user interacts an individual element in an array, I mark it as seen, and don't show it to the user

What is the best way to implement this for multiple users? It seems fairly simple for a single user, where you can just modify the array to have a seen boolean and then just filter it, but when you have multiple users, what would be the best way to handle that?

Would I create a separate "elementsMarkedAsSeen" file for each user? and then filter it from there? Should I store the elements in the array that the user has seen? or the elements the user has not seen? What happens if the array of elements changes?

I'm just looking for a high level best practice explanation that won't cause me trouble later on. I'll do my own research from there.

The most common approach is to keep a single value for each user that identifies the most recent message they have seen, and assume they've seen all messages before that one to. So this can either be a timestamp of that message, its ID, or anything else that you can use to identify the message.

If your users can read messages out of order and you want to track viewing each individual message, you have two options:

  1. Store the UID of each user that has seen a message in or under that message.
  2. Store the ID of each message that a user has seen in or under that user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM