4
1 Comment

How to handle deleting messages in direct messaging system?

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?

  1. 2

    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

    • Can User A and User B have more than one conversation, or is a conversation defined by its participants?

    ----

    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:

    • Delete for everyone
    • Delete for just me

    It seems that you're using the second definition

    So, deleting a conversation:

    • Delete all messages for me in this conversation
    • Ensure that the server won't send me these messages under any circumstances
    • Temporarily hide the conversation in the chat pane

    ----

    To answer your questions with a solution:

    Now where I'm stuck is, what happens if User A replies to User B?

    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

    Do I display the whole previously deleted chain on User Bs side?

    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 IMO

    Do I start a new conversation on User B's side but continue the chain on User A's?

    Yes

    Do I start a new conversation on User A and User Bs side?

    No

    So instead I just remove User B from the conversation.

    Don't do this, User A should not be informed that a conversation has been deleted (unless this is tied in with "block" functionality)

Trending on Indie Hackers
After 10M+ Views, 13k+ Upvotes: The Reddit Strategy That Worked for Me! 27 comments 🔥Roast my one-man design agency website 18 comments Launch on Product Hunt after 5 months of work! 16 comments Getting first 908 Paid Signups by Spending $353 ONLY. 13 comments Started as a Goodreads alternative, now it's taking a life of its own 12 comments I Sold My AI Startup for $1,500 and I'm Really Happy About It 11 comments