I am trying to build a messaging/chat system. which can store conversation between two people in a chronological order. Also if User A deletes the conversation User B still should have access the conversation until he wishes to delete them.
-
Inbox – All the messages recieved by the user from various users will be displayed with the latest message from that particular thread.
-
Conversation Screen – Chronological order of the conversation between the User A and User B
This is the basic structure of the database i have come up with. Should i store the messages twice in the database ?
- id
- to_id
- from_id
- message
- timestamp
- read
I would use a lookup table for the messages that would store who has the rights to view that message
That way if a user deletes their message they are actually just deleting their relationship to the message not the message itself. you just remove them from the messageUsers table. or set a active field to 1 or 0.