开发者

Read status of messages in Inbox

I am developing a messaging inbox system that uses a thread-based layout for messages. What I'm struggling with at the moment is updating the read status of the messages. Perhaps I have got the structure wrong so I could do with some guidance.

Here is what I have:

Table messages
==============
id
thread_id
from_user_id
subject
body
sent_date

Table message_threads
=====================
id
message_id
owner_id
member_id
owner_read
member_read

In the message_threads table, 'owner' refers to the user who started the thread, and 'member' refers to the other participant. A user's inbox will contain threads they have created themselves (owner), and also threads created by other users to which they have replied to (member).

The logic for setting the read status is as follows:

  • if owner sends a reply: 'member_read' field is set to 0 (unread), 'owner_read' field is set to 1 (read)

  • if member sends a reply: 'owner_read' field is set to 0 (unread), 'member_read' field is set to 1 (read)

Now I don开发者_开发技巧't think this is entirely the correct approach, because suppose a member wants to sort messages in their inbox by read status - however a user can be both an owner and a member, and there are two read fields in the table. So this sort would not be correct.

Any suggestions on how I should go about this?

EDIT: Here is an exaple scenario:

  • User 1 sends Thread A to User 2
    • Thread A appears in User 2's inbox (status 0: unread)

  • User 2 opens Thread A
    • Thread A status set to 1 (read)

  • User 2 replies to Thread A
    • Thread A status in User 1's inbox (status 0: unread)
    • Thread A status in User 2's inbox (status 1: read)

  • User 1 opens Thread A
    • Thread A status set to 1 (read)

  • User 1 replies to Thread A
    • Thread A status in User 1's inbox (status 1: read)
    • Thread A status in User 2's inbox (status 0: unread)


The only "read" status is for messages that didn't originate from you. a reply to a recipient is marked read when opened. The sender doesn't care if it was read unless you want "receipt confirmation"

So - with that in mind here is what i think it should look like (i didn't include all fields in messages):

Table "users"

id
name

table "messages"

id (int)
parent_id (int)
from_user_id (id)
to_user_id
read (bit/bool)
message (text)

Let me know if I didn't understand you right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜