Reputation: 3788
Backgroun: I'm trying to build a private messaging system in Mysql with conv view.
I have a msg_received tbl which looks like this
id from_member_id to_member_id message_id
1 123 456 101
2 456 123 102
3 123 456 103
4 456 123 103
So when userA (id: 123) views his conv history; he sees the 2 messages he has sent to userB (id:456) and and 2 messages he has received from userB (id: 456). So he sees a total of 4 messages. Same for userB; he sees a total of 4 messages.
The problem is that I would like to allow userA to delete one of those messages. Lets say that he wants to delete msg_id 103. So now userA only sees 3 messages.
The problem is that when userB tries to view the conv history; he also sees only 3 messages instead of the 4 that he should. This is because he hasn't deleted any messages and expects to see the full history.
Can you guys provide any tips?
Upvotes: 2
Views: 917
Reputation: 21
Take a column in table named hide_from,
check the sample table for reference
suppose we have two unique ids for the users , e.g. those ids are 2 and 5, in your chat table you would have 2 as from_id as well as to_id and vise-e-versa.
If user 2 deletes the chat thread then insert 2 in hide_from, now if user 5 deletes the chat thread then check if hide_from is not NULL && hide_from = 2, delete all the messages of 2 & 5
Upvotes: 1
Reputation: 26861
Add a single flag status in which keep you can hold:
0 - unread
1 - read
2 - deleted by sender
3 - deleted by recipient
4 - spam, etc
Upvotes: 0
Reputation: 81724
One simple approach would be to add two columns, for "from_user_deleted" and "to_user_deleted", and then respect those columns when showing the message lists (and clean up when both flags are set.)
Upvotes: 1
Reputation: 255005
Add 2 flags: deleted_by_sender
and deleted_by_recipient
.
When only one user "deleted" - set up approproate flag. When both flags = 1 - delete the record physically.
Also - now you'll need to add AND deleted_by_recipient = 0
condition to your WHERE
Upvotes: 3