我想为1:1和群组聊天活动创建聊天应用程序。
我已经为两种情况创建了一个架构:
{ // group
"id": 1 // id of the group
"name": "Chat Group" // name of group; if there are more than 2 members
"members": [ "member1", "member2", ...] // ids of the group chat members; only they have access to the JSON document
"chatlog": [ "timestamp1": ["member1", "message1"], "timestamp2": ["member2", "message2"], ...] // who sent which message in chronological order
}
将用户的访问列表存储在如上所示的“成员”数组中会更好,还是"chat_groups"
的解决方案更好:
{ // user
"id": 1 // id of the user
"name": "Max" // name of the user
"chat_groups": [ "1", "2", ...] // ids of the groups, the user is a member of
}
根据this帖子,应该有3个节点,user
,convo
和messages
。 convo
决定是1:1聊天还是群聊。另外,您可以在creator
中添加另一个属性作为convo
来设置组管理员权限。
示例:用户
{ // user
"id": 123,
"name": "Omkar Todkar"
}
示例: Convo
{ // group
"id": 1,
"members": [123, 234, 345]
"creator": 123
},
{ // 1:1
"id": 2,
"members": [123, 345]
"creator": 123
}
示例:消息
{ // group message
"convo_id: 1,
"author": 123,
"content": "Welcome, to our new group."
},
{ // 1:1 message
"convo_id: 2,
"author": 123,
"content": "Hey, you wanna join us in group?."
},
{ // 1:1 message
"convo_id: 2,
"author": 345,
"content": "Sure, I would love to join."
},
{ // group chat
"convo_id: 1,
"author": 234,
"content": "Hi, Happy to see you both here."
}