I am building a chat app using Firebase. I have designed a database structure, but would like to get some insight on it whether it could be structured better.
Here is how it looks:
incoming_messages:
userID:
sender_userID:
-KOkGD9n-ysFqX2DtyKp:
body: "Hello world!"
timestamp: 124245345346
-KOfHTD9n-xsEqX289xGc:
body: "My second message!"
timestamp: 124245345346
Every user is observing their node (by userID
) of the incoming_messages for updates. The conversations are identified by who sent them to the user, while messages have auto IDs
Same goes for the sent messages of a particular user, and who he sent it to:
sent_messages:
userID:
receiver_userID:
-KOkGD9n-ysFqX2DtyKp:
body: "Hello!"
timestamp: 124245345346
-KOfHTD9n-xsEqX289xGc:
body: "Haha cool!"
timestamp: 124245345346