Answer the question
In order to leave comments, you need to log in
Creating a unique chat: sql, node, socket.io?
Hello!
I want to know your opinion about the organization of creating a private chat. In this case, without experience, I would like to learn information from more experienced.
Rules for private chat: There is role A and B. Only role A can start a chat with role B, otherwise there should be no chat. Chat can contain only 2 persons.
From the sql side:
1 - If role A started a chat with B, then columns will be created in the table chat
2 id, user_id, second_user_id
- All correspondence will be stored in a table chat_messages
where there are columns chat_id, user_id, message
From the node side:
1 - before creating a chat, check that only role A creates a chat with B
2 - get chat id and create/move a room with this id in socket.io
From socket side:
1 - receive all messages in a specific room and send everything to the database
. Will such a structure work? Or is there a better option?
I would be very grateful for any help!
Answer the question
In order to leave comments, you need to log in
There is role A and B. Only role A can start a chat with role B
Chat can only contain 2 persons
Well, at first glance, there are no problems, especially if you deliberately omitted the part with registering users and assigning roles to them. Well, I would add an "access" column to each entry in chat_messages with access only to the specified roles (which may include roles A and B and I would also add the "FBI" role to access the system administrator's chat), otherwise you have someone anything to the correspondence will get access. And, of course, the ability to delete messages (although I would not delete, but simply change the access rights to the record to "only FBI", as is implemented, for example, in VK and TG).
It remains the simplest and fastest - implementation.
And how much does it cost to create such a chat? I tried to ask the question myself but the moderator didn't allow it. I can't really find the average price online...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question