I'm building a simple direct messaging system for my community. I am not utilizing sockets for now, just plain old storing messages in my DB that users will see when they load their account page. I want to store messages in a "chain" or "conversation", so messages between User A and User B are grouped together in logical order, same between User A and User C, etc. etc.
What I'm having trouble figuring out is how to handle deleting messages. Say User A messages User B, and User B replies to User A. Both users now see two messages in the chain (one sent one received). Now say User B deletes the conversation on their side. I wouldn't want to delete the conversation on User A's side, what if they have valuable info in the chat. So instead I just remove User B from the conversation. Now where I'm stuck is, what happens if User A replies to User B? Do I start a new conversation on User B's side but continue the chain on User A's? Do I display the whole previously deleted chain on User Bs side? Do I start a new conversation on User A and User Bs side?
It feels like no matter what it would be confusing for one of the users. Is there a simpler way to handle this? Any good examples of non-realtime messaging systems you could point me to?
TL;DR: Use a "deleted message" placeholder message (ideally in a different color than your regular color scheme).
----
You first need to define what a "conversation" is
----
For the above, I assume that User A and User B will always have one "conversation", and any additional conversations would fall under a "group chat" feature.
Next, you want to define what "deleting" a message is:
It seems that you're using the second definition
So, deleting a conversation:
----
To answer your questions with a solution:
If you have a "reply" function, then the parent chat message should be marked as deleted for User B. User B will see a "deleted message" placeholder, and the reply will be a reply to this.
If you don't, treat it from the User B UI as a new conversation, possibly with a placeholder stating that previous messages have been deleted.
User A will not see any UI changes
No, User B has deleted the messages, this should be stored server-side to ensure that User B cannot retrieve their messages from the UI.
Note: These are some privacy issues here - they will likely be able to see "deleted" messages via a GDPR request
*, which may frustrate users. Have a think about if you want to educate users about this - but it's probably easier to treat it as out of scope.*Unless encryption is involved, which would get complex, messy and would require much more thought than you should put in IMOYes
No
Don't do this, User A should not be informed that a conversation has been deleted (unless this is tied in with "block" functionality)