数据库设计用于在人们之间存储聊天消息 [英] Database Design for storing Chat Messages between people
问题描述
我正在尝试建立一个消息/聊天系统。它可以按时间顺序存储两个人之间的对话。此外,如果用户A删除会话用户B仍然应该访问会话,直到他希望删除它们。
I am trying to build a messaging/chat system. which can store conversation between two people in a chronological order. Also if User A deletes the conversation User B still should have access the conversation until he wishes to delete them.
Inbox - All the messages recieved by the user from various users will be displayed with the latest message from that particular thread.
对话窗口 - 用户之间对话的时间顺序A和用户B
Conversation Screen - Chronological order of the conversation between the User A and User B
这是我想出的数据库的基本结构。我应该在数据库中存储两次消息吗?
This is the basic structure of the database i have come up with. Should i store the messages twice in the database ?
- id
- to_id
- from_id
- 讯息
- 时间戳记
- 阅读
- id
- to_id
- from_id
- message
- timestamp
- read
推荐答案
我将使用查找表来存储谁有权查看该邮件
I would use a lookup table for the messages that would store who has the rights to view that message
table->message | table->messageUsers
id->0, message->'hi', user_id->1 user_id->1, message_id->0
user_id->2, message_id->0
这样,如果用户删除他们的邮件,消息不是消息本身。您只需从messageUsers表中删除它们。或将活动字段设置为1或0。
That way if a user deletes their message they are actually just deleting their relationship to the message not the message itself. you just remove them from the messageUsers table. or set a active field to 1 or 0.
这篇关于数据库设计用于在人们之间存储聊天消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!