Set read status for a group chat using Firebase

2020-07-29 23:11发布

问题:

I am trying to make a chat application containing individual chat between users and group chat using Firebase. And I would like to make a read status for each message, Now the problem is, consider a group chat have a node

> groupId---->
>         --->messageId
>                  -->userId
>                  -->messageType
>                  -->text

My implimentation is like if a user sending a message to a group that will be added under group id with message id node and who are all listening to the group will get that child message now I want to keep a status for who are all read the message. I can handle it by keeping a local status, But if the user logging from another device how can I handle that?

回答1:

If you want to track whether a user had read each message, you'll need to store that in your database:

read_messages_per_user
  <userId>
    <messageId>: true

This may become a lot of data over time. So a more efficient (but less specific) variant is to store the last message that the user read.

last_read_messageId_per_user
  <userId>: <messageId>