Database Design for storing Chat Messages between people

前端 未结 3 819
失恋的感觉
失恋的感觉 2021-02-01 20:37

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 shou

3条回答
  •  耶瑟儿~
    2021-02-01 20:58

    I would use a lookup table for the messages that would store who has the rights to view that message

    table->message                   |    table->messageUsers
    id->0, message->'hi', user_id->1      user_id->1, message_id->0
                                          user_id->2, message_id->0
    

    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.

提交回复
热议问题