1

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?

Vaisakh N
  • 780
  • 1
  • 11
  • 27

1 Answers1

9

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>
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807