我正在firebase中实现一对一聊天。我对数据结构有点混淆。 firechat有最佳实践,但这不适用于群聊而非一对一聊天。
我设计了以下数据结构,任何人都可以建议更好的方法或点校正。
chat-messages/
<chat-id>
<message-id>
userId - The id of the user that sent the message.
name - The name of the user that sent the message.
message - The content of the message.
timestamp - The time at which the message was sent.
chat-metadata/
<chat-id>
createdAt - The time at which the room was created.
createdByUserId- The id of the user that created the room.
id - The id of the room.
my-chats/
<user-id>
<other-user-id>
chatId - The chat id
users/
<user-id>
id - The id of the user.
name - The display name of the user.
在my-chats
中,它会显示用户已完成聊天的所有人。因此,对于username1和username2,将为各个用户提供每个条目,如
my-chats
username1
username2
chatId:-K6OqUkJRDpnOahGQ4rO
username2
username1
chatId:-K6OqUkJRDpnOahGQ4rO