我正在使用Firebase构建聊天应用。我已经设计了一个数据库结构,但是想要了解它是否可以更好地构建它。
以下是它的外观:
incoming_messages:
userID:
sender_userID:
-KOkGD9n-ysFqX2DtyKp:
body: "Hello world!"
timestamp: 124245345346
-KOfHTD9n-xsEqX289xGc:
body: "My second message!"
timestamp: 124245345346
每个用户都在观察他们的incoming_messages节点(userID
)以获取更新。对话由谁将其发送给用户来识别,而消息具有自动ID
同样适用于特定用户的已发送消息,以及他将其发送给谁:
sent_messages:
userID:
receiver_userID:
-KOkGD9n-ysFqX2DtyKp:
body: "Hello!"
timestamp: 124245345346
-KOfHTD9n-xsEqX289xGc:
body: "Haha cool!"
timestamp: 124245345346