Reputation: 5458
I'm looking at creating a user messaging system (similar to Facebook).
What I want to know is essentially what should the table structure look like? The requirements I have are as follows:
Messages are exchanged between users - a sender can select multiple users to send a message to.
Messages are displayed in a thread-style layout, as a 1-1 conversation. i.e. each recipient's reply will appear in it's own thread.
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. However the other user can still access the thread if he/she hasn't deleted it from his/her inbox.
Here is what I have at the moment:
Table messages ============== id (PK) user_id (from) subject body sent_at Table message_recipients ======================== message_id (PK) user_id (PK) read_status
EDIT: What about the following:
Table messages ============== id (PK) thread_id user_id (from) body sent_at Table threads ============= id (PK) user_id (from) subject Table thread_recipients ======================= thread_id (PK) user_id (PK) read_status sender_deleted recipient_deleted
Upvotes: 2
Views: 2811
Reputation: 978
@Angelo R. Would like to know why we require the Thread Table? This isn't any discussion board. If you want to retrieve the whole thread/conversation of messages you can simply query by source AND recipient ID. Plus, if you use Thread, nothing bad. But what in this situation If new message - new thread_id (automatically created), If replied to existing conversation, you have the thread_id, but what if you are creating a new message (say like facebook popup), you don't know whether there was any previous conversation or if thread_id is available or not unless you execute a special query to it. This was my thought. Tell me if I might be wrong somewhere.
Upvotes: 0
Reputation: 2341
I would suggest having the following at least:
Users, Threads, Messages
From there you could simply assign a couple flags to your thread (to_user_deleted, from_user_deleted) that would be updated accordingly.
There a lot more things to consider of course, such what kinds of things you want to account for. For example:
You need to take all of these into account while designing your database.
Upvotes: 4
Reputation: 85378
Why not use something like Jabber (example: OpenFire or Web Client)
If you need PHP to interact with it you could use something like:
http://code.google.com/p/xmpphp/ or http://code.google.com/p/jaxl/
Upvotes: 0