Search code examples
phpmysqlprivate-messaging

PHP Private Message (PM) System


I am planning making a PM system for my users, overall it seems easy enough, but the way I have seen tutorials making PM systems, there is one problem.

In the way i planned it to work, there would be rows like, user_from, user_to and then the message - user_from would be the sender, and will see the message in his send messages, user_to will be the receiver and will see the message in his inbox. BUT, what if a user wants to delete a message from their sent folder, but the other user does not want to delete it from their inbox ??

Is there any simple way doing this ?

It could also be nice, to have the messages in conversations, like Gmail and Facebook, but that is maybe to hard to code (any tutorials appreciated)?


Solution

  • You can fix the issue a few ways, but I would probably add a couple flags (from_deleted, to_deleted) to the table:

    • Instead of deleting the message, update the appropriate flag to 1.
    • When listing messages, filter out those that have been flagged.
    • You can setup the script so that after flagging, if both fields are flagged then you can actually delete the row.