Reputation: 151
I am try to design a structure for chat application include private message and
groups i by using real time firebase
i don't know how to design the structure
any help please
i am try to do something like this is that true
Users
|
|_USER1
| |
| |__FRIENDS
|
|_USER2
|
|__FRIENDS
Upvotes: 1
Views: 3581
Reputation: 600006
You'll typically end up modeling the "chat rooms" in the database. So that each conversation (that users may see when they start the app), shows up as a separate node under some root list. You may want to separate the main metadata of each conversation from its actual messages and its participants.
So:
Chats
chat1
title: "...."
lastUpdated: ...
chat2
title: "...."
lastUpdated: ...
Messages
chat1
message1: { ... }
message2: { ... }
chat2
message3: { ... }
message3: { ... }
Participants
chat1
userid1: true
userid2: true
chat2
userid1: true
userid3: true
userid4: true
userid5: true
By using the same keys (chat1
, chat2
) for the nodes in each list, you can easily look up the data for a complete chat when needed. But by keeping them in separate top-level lists, you can better secure the app, and better control how much data is loaded.
Also see:
Upvotes: 7