I am trying to structure a firebase database for chat system. What I wanted to achieve is after user successfully logged in, they will see a list of message they have sent to different users. Each of the message preview will show the last message. Then, user can select on the message to view the full chat details. It should work like the Facebook Messenger.
My design structure as such:
chatMessage
sender *(Assume this one is user)*
threads
threadID1
messageID1
datetime, content, receiver, status
messageID2
datetime, content, receiver, status
threadID2
messageID1
datetime, content, receiver, status
messageID2
datetime, content, receiver, status
sender *(Assume this one is admin)*
threads
threadID1
messageID1
datetime, content, receiver, status
messageID2
datetime, content, receiver, status
The design above allows me to know let's say userID1 logged in, I can retrieve all the messages he sent. However, I am not able to know if there is any reply prior to the message and therefore I am not able to retrieve the last message.
How can I actually restructure it so that I can achieve what I mentioned above? Any suggestions?
Thanks!