I am using firebase chat application with angularJs. My requirement is message send user to user only not send to all users. So, is there any way to do user to user chat?
Asked
Active
Viewed 1,546 times
2

Frank van Puffelen
- 565,676
- 79
- 828
- 807

shefali kapoor
- 21
- 2
-
Yes. You can do peer to peer chat, but you have to design your collections accordingly to handle this. see my answer below. – srinivas Jul 05 '17 at 13:40
-
Peer to peer chat is really just group chat with only two participants. One simple way to accomplish this is to model the chat room names after the participants. See my explanation here: http://stackoverflow.com/questions/33540479/best-way-to-manage-chat-channels-in-firebase – Frank van Puffelen Jul 05 '17 at 14:06
1 Answers
5
For example - you could create a global chats collection. When you want two users A & B to chat you can create a UID under chats and store it under each user A & B.
Then whenever you have a send messages, you just get the chat id from under the user and add the message in the global chat collection.
Firebase
-Users
-A
-Chats
-Id of User B
-chatid1
-B
-Chats
-Id of user A
-chatid
-..
-..
-Chats
-chatid1
-message1
-message2
-..
-chatid2
-..

srinivas
- 4,778
- 2
- 32
- 43