设计问题:您将如何设计消息/收件箱系统?

发布于 2024-07-05 19:15:01 字数 170 浏览 6 评论 0原文

许多网站都有在用户之间发送消息的概念。 当您向其他用户发送消息时,该消息将显示在他们的收件箱中。 您可以回复该消息,它会在该消息线程中显示为新条目。

您应该能够看到您是否已经阅读了给定的消息,并且获得新回复的消息应该能够位于顶部。

您将如何设计类(或表或其他)来支持这样的系统?

Many websites have the concept of sending messages from user to user. When you send a message to another user, the message would show up in their inbox. You could respond to the message, and it would show up as a new entry in that message thread.

You should be able to see if you've read a given message already, and messages that have got a new response should be able to be at the top.

How would you design the classes (or tables or whatever) to support such a system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

少女七分熟 2024-07-12 19:15:01

您可能希望扩展 Owen 的架构以支持批量消息,其中消息仅存储一次。 还进行了修改,因此只有一个发送者和许多接收者(此方案中永远不会有多个发送者)

user
  id
  name

message
  id
  recipient_id
  content_id 
  date_time_sent
  date_time_read
  response_to_message_id (refers to the email this one is in response to - threading)
  expires
  importance
  flags (read, read reply, etc)

content
  id
  message_id
  sender_id 
  title
  message

当然,还可以添加许多其他功能,但大多数人在想到“电子邮件”时会想到上述功能”。

-亚当

You might want to extend Owen's schema to support bulk messages where the message is stored only once. Also modified so there's only one sender, and many receivers (there's never more than one sender in this scheme)

user
  id
  name

message
  id
  recipient_id
  content_id 
  date_time_sent
  date_time_read
  response_to_message_id (refers to the email this one is in response to - threading)
  expires
  importance
  flags (read, read reply, etc)

content
  id
  message_id
  sender_id 
  title
  message

There are many, many other features that could be added, of course, but most people think of the above features when they think "email".

-Adam

策马西风 2024-07-12 19:15:01

这是一个相当简单的表结构。 发件人/发件人、主题,然后是消息。 现在重要的是日期字段。 DateSent 告诉消息何时发送,DateRead 告诉消息已被读取,DateDeletedTo 告诉 TO 用户删除了它,DateDeletedFROM 告诉 FROM 用户删除了它(这些是本例中的逻辑删除)。

tblMessage
ID  BIGINT 
ToUserID GUID/BIGINT
FromUserID GUID/BIGINT
Subject NVARCHAR(150)
Message NVARCHAR(Max)
DateDeletedFrom DATETIME
DateDeletedTo DATETIME
DateSent DATETIME
DateRead DATETIME

It's a rather simple table structure. A to/from, subject and then the message. Now the important thing is the date fields. The DateSent tells when it was sent, the DateRead tells that the message was read, and the DateDeletedTo tells that the TO user deleted it, and the DateDeletedFROM tells that the FROM user deleted it (these are logical deletes for this example).

tblMessage
ID  BIGINT 
ToUserID GUID/BIGINT
FromUserID GUID/BIGINT
Subject NVARCHAR(150)
Message NVARCHAR(Max)
DateDeletedFrom DATETIME
DateDeletedTo DATETIME
DateSent DATETIME
DateRead DATETIME
很酷又爱笑 2024-07-12 19:15:01
user
 id
 name

messages
 id
 to_user_id
 from_user_id
 title
 date

message_post
 id
 message_id
 user_id
 message
 date

类会反映这种模式

user
 id
 name

messages
 id
 to_user_id
 from_user_id
 title
 date

message_post
 id
 message_id
 user_id
 message
 date

classes would reflect this sort of schema

实际上,我这样做是作为工作中一些内部发展的一部分。 创建一个名为 [Messages] 的表并为其指定以下列。

  • mID(消息ID)
  • from_user
  • to_user
  • 消息
  • 时间
  • tID(线程ID)
  • 读取(布尔值)

类似的东西应该适用于表设计。 这些类取决于您在什么系统上设计它。

I'm actually doing this as part of some internal development at work. Make a table called [Messages] and give it the following columns.

  • mID (message ID)
  • from_user
  • to_user
  • message
  • time
  • tID (thread ID)
  • read (a boolean)

Something like that should work for the table design. The classes depend on what system you're designing it on.

天荒地未老 2024-07-12 19:15:01
Table Message:
id INTEGER
recipient_id INTEGER -- FK to users table
sender_id INTEGER -- ditto
subject VARCHAR
body TEXT

Table Thread
parent_id -- FK to message table
child_id -- FK to message table

然后,您可以通过线程表来获取消息线程。

Table Message:
id INTEGER
recipient_id INTEGER -- FK to users table
sender_id INTEGER -- ditto
subject VARCHAR
body TEXT

Table Thread
parent_id -- FK to message table
child_id -- FK to message table

Then, you could just go through the Thread table to get a thread of messages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文