I'm currently developing a user messaging system (similar to Facebook) for my existing site. I already have a users table and just need to integrate a messaging system now.
I started a thread on this yesterday (User messaging system) and made some progress but the structure has changed quite a bit so I'm starting a new question.
What I want to know is essentially what should the table structure look like? The requirements are as follows:
Messages are exchanged between users, and a sender can send a message to multiple recipients.
Messages are displayed in a thread-style layout, as a 1-1 conversation. i.e. each recipient's reply will appear in its own thread.
Once a thread is created it will appear in the senders 'sent messages' folder - it will not appear in their inbox unless the recipient sends a reply.
Individual messages cannot be deleted, however a thread can be deleted. Deleting a thread doesn't delete any messages, it just removes that thread from the user's inbox, (or 'sent messages' folder). The other user will still have access to the thread if he/she hasn't deleted it from his/her inbox (or 'sent messages' folder).
When a message or reply is sent, the 'read status' is set to 'unread' - but that should not affect the sender. i.e. only the recipient should see it as 'unread'.
Here is what I have at the moment:
Table messages ============== id thread_id from_user_id subject body sent_date Table message_threads ===================== id message_id to_user_id from_user_id read_status
Something else to think about is when sending the same message to multiple recipients, should we store a seperate message for each recipient, or just one message?
Any guidance would be highly appreciated.