Y
Y
Yuri Kulaxyz2020-03-15 12:56:53
Database design
Yuri Kulaxyz, 2020-03-15 12:56:53

How are contacts connected in messengers?

I am writing an API for a new messenger, I stopped at the moment of connecting contacts. I do not quite understand how to implement the chats themselves now.
Without contacts, everything is simple: there are tables users, chats, participants, messages . And when the user views the chat itself, I get the user object through the participants table. And I already display the name, nickname and avatar specified by the user. Now the question is what to do with contacts .
I will state my assumptions:
Create a contacts table , where to store the owner_id , and name, surname, phone . Then when I give the user object to the front , add the contacts collection to it(that is, all records from the contacts table WHERE owner_id={user->id}). And already at the front, the developer will need to compare chat.participants with each entry from user.contacts and display the name if the phone property matches, and so on. from the corresponding object from contacts.
This logic seems to me too complicated. Tell me a more convenient option for integrating contacts. Maybe someone knows how this is implemented in popular instant messengers like Telegram, WhatsApp?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Kuznetsov, 2020-04-06
@pluseg

Your logic is quite correct: send separate chat messages with IDs, separate directories of user IDs and their contact details. It is better to shift the task of matching chat participants and their profiles to the client, who will be able to store this table of contacts in his local database (localstorage) and periodically synchronize. Of course, the first time the sync will take longer.
- Most often, popular instant messengers immediately create a user for each person from contacts. And yes, they store a personal table of contact names for each user. For example, this is done in Skype and Whatsapp. In Telegram, a user is not created until he registers himself, but there they do not give the opportunity to "rename" his contacts - as the user named himself, it will be displayed.
- NoSQL databases are used for such tasks, which speeds up queries and removes the need for caching.
- Databases are sharded by user_id in order to get all user data as quickly as possible, including his contacts, chats, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question