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

时间:2021-07-01 12:52:02

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?

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

5 个解决方案

#1


1  

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

类会反映这种模式

#2


1  

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)

您可能希望扩展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

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

#3


0  

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).

这是一个相当简单的表结构。 A到/来自主题然后是消息。现在重要的是日期字段。 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

#4


0  

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

我实际上是在做一些内部开发工作的一部分。创建一个名为[Messages]的表,并为其提供以下列。

  • mID (message ID)
  • mID(消息ID)

  • from_user
  • to_user
  • message
  • time
  • tID (thread ID)
  • tID(线程ID)

  • read (a boolean)
  • 读(布尔值)

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

这样的东西应该适用于桌面设计。这些类取决于您正在设计的系统。

#5


0  

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.

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

#1


1  

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

类会反映这种模式

#2


1  

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)

您可能希望扩展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

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

#3


0  

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).

这是一个相当简单的表结构。 A到/来自主题然后是消息。现在重要的是日期字段。 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

#4


0  

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

我实际上是在做一些内部开发工作的一部分。创建一个名为[Messages]的表,并为其提供以下列。

  • mID (message ID)
  • mID(消息ID)

  • from_user
  • to_user
  • message
  • time
  • tID (thread ID)
  • tID(线程ID)

  • read (a boolean)
  • 读(布尔值)

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

这样的东西应该适用于桌面设计。这些类取决于您正在设计的系统。

#5


0  

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.

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