您将如何创建线程消息系统?

发布于 2024-07-13 04:47:06 字数 641 浏览 6 评论 0原文

我想知道线程消息系统的表结构。

我认为将有 3 个表:

- message_thread
    - id
    - subject
- message_user
    - thread_id
    - user_id
    - thread_status (unread, read, trash, deleted)
- message
    - date (date sent)
    - sent_user_id
    - message

每个 message_thread 在 message_thread 中将有 1 条记录。 每个用户都会在 message_user 中拥有一条与该线程相关的记录,以及该线程的读取/删除状态。 (message_user 还可能包含一些关于何时发生不同状态的日期时间字段。)消息表将包含消息、发送消息的用户和时间。

该系统最终的工作方式将类似于 Facebook 或看起来像 Gmail 的(尽管不是基于电子邮件)。

必需:

  • 线程中涉及超过 2 个用户,
  • 每个用户必须拥有自己的线程读取/删除状态

这是您设置的方式吗?

I'm wondering about the table structure for a threaded messaging system.

I'm thinking there will be 3 tables:

- message_thread
    - id
    - subject
- message_user
    - thread_id
    - user_id
    - thread_status (unread, read, trash, deleted)
- message
    - date (date sent)
    - sent_user_id
    - message

Each message_thread would have 1 record in message_thread. Each user would have a record in message_user relating them to that thread and also their read/deleted status for that thread. (message_user might also contain some datetime fields as to when the different statuses occured.) The message table would contain the messages, the user that sent them and the time.

The system in the end would work similar to Facebook or looks like Gmail's (although not based on email).

Required:

  • more than 2 users involved in the thread
  • each user must have their own read/delete status for the thread

Is this the way you'd set it up?

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

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

发布评论

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

评论(2

你丑哭了我 2024-07-20 04:47:06

尝试一个表:

messages
  id (INT)
  user_id (INT, ref to users table)
  subject (CHAR)
  parent_id (INT, ref to messages table, NULL if head of thread)
  content (TEXT),
  (other per-message attributes)

允许线程化,并且每条消息都有自己的主题。

要添加阅读状态,请添加一个将用户链接到消息的多对多表,其中表中的条目表示用户已阅读该消息。

Try one table:

messages
  id (INT)
  user_id (INT, ref to users table)
  subject (CHAR)
  parent_id (INT, ref to messages table, NULL if head of thread)
  content (TEXT),
  (other per-message attributes)

Allows threading, as well as for each message to have it's own subject.

To add read status, add a many-to-many table linking users to messages, where an entry in the table means the user's read that message.

找个人就嫁了吧 2024-07-20 04:47:06

我将添加一个状态日志记录表,其中包含 user_id、thread_id、status_id 和状态更改的日期。

我还将合并 message 和 message_thread 表,因为它们看起来将是 1 对 1 并且可以合并。

I'd add a status logging table with user_id, thread_id, status_id and the date the status changed.

I would also combine the message and message_thread tables as it appears those will be a 1 to 1 and could be combined.

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