I want to make one-to-one messaging. Messaging login will be required.
Like whatsapp or instagram. How should I establish its logic?
I want to do:
- Saving messages in the database,
- Showing old messages when messaging with the user is started,
- To start instant messaging.
- Message notifications need to be automatic
Do I need to create a channel for each user (realtime)? How can i save message and realtime. Can you help me how to do it?
Hi @Paradise_Little,
Perhaps the following approach works for you:
- Create the âConversationsâ table:
a. members (1:N Users)
- Create the âConversationMessagesâ table:
a. content (string)
b. conversation (1:1 Conversation)
c. conversationObjectId (string) â This is important!
d. read (boolean)
- Rely on the Real-time database approach instead of RT Messaging. Specifically the Conditional Delivery section.
- In order to get the messages history, you need to request the existing ConversationMessages records that match the conversation and the member. Here is a node.js service with that (careful with the paging, consider messages will be added frequently and your offset must take care of that; in this case, I always request the first 10 records and ignore the ones I already have in the UI based on the created date):
.
- In your frontend, subscribe to the Create event for objects with the appropriate conversationObjectId: .
- Consider to also ignore the âjust sent messagesâ to avoid messages duplicity. You can either extend that where clause or just dismiss it once the RT handler notifies of it.
I hope itâs a bit usefulñ
1 Like
Thank you for response.
You explained it very well. I donât need to use the channel part so am I correct?
Will it be enough to create the tables and listen to the ConversationMessages Table?
Iâve not found any disadvantage so far. As long as you persist the message, it would work.
Hi, @Paradise_Little
Did the above option solve your issue?
Regards,
Marina