I am trying to structure a firebase realtime database for group and personal chat app. 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. My Question is how to Query the Chats by UserId?
I am following data structure below :
{
"chats": {
"$chatId1": {
"title": "Historical Tech Pioneers",
"lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
"timestamp": 1459361875666,
userIds:{
"$userId1":true,
"$userId2":true
}
},
"$chatId2": { ... },
"$chatId3": { ... }
},
"messages": {
"$chatId1": {
"m1": {
"name": "eclarke",
"message": "The relay seems to be malfunctioning.",
"timestamp": 1459361875337
},
"m2": { ... },
"m3": { ... }
},
"$chatId2": { ... },
"$chatId3": { ... }
}
}