I want to make my chat, and how best to save messages and divide them into rooms? For example, there is a message text I save it in the database with the conversation identifier date and other parameters, and when the user enters the application and selects the desired room, a request is sent to the server with the room identifier and a response with ten or more recent messages arrives. This is my vision of a solution to a problem, so I’m interested to have any other solutions to this problem? as for example arranged in pubnub and so on?

    2 answers 2

    Do not believe it is currently engaged in just such a chat. The server has a database with registered users. And for messages - another database. Each chat corresponds to a table. In each table - messages. At startup, the application sends a request to the server and I receive a JSON array with rooms. When clicking on a room, a request is sent to receive the last 30 messages. When scrolling up to the end, auto-loading of messages occurs. It seems your idea is an ideal. IMHO, any developer would do that.

      We make two tables:

      1. Room
      2. Message

      The message relates to the many-to-one room. That is, one room can have many messages.

      • In the first table, create an entry for each chat room.
      • The second table creates messages with a link to one of the rooms.

      That's it. Not for highly loaded systems such a solution is more than enough, you can store tens of thousands, or even hundreds of thousands of messages without problems. Although most often store so many messages there is no need.