0
votes

I would like to create a one-to-one iOS chat app using Firebase. The only examples I found are for group chat implementations and I am not sure how to structure the database for a one-to-one chat.

My main question is: How do I listen for new chats/messages? Let's say user1 wants to chat with user2 and they have not talked before. How does user1 send a message to user2?

Could someone point me in the right direction for implementing a one-to-one chat with Firebase?

Thanks!

1
That is an incredibly broad topic. But if you're wondering how to get the users into the same chat room, see stackoverflow.com/questions/33540479/… - Frank van Puffelen
Thank you, that did clear things up a bit! But how do I let user2 know that user1 sent him a message? What databass changes should user2 be observing? - Balázs Vincze

1 Answers

2
votes

Here's a very high level structure to start.

uid_0 will be observing their incoming_messages node, and uid_1 will be observing their incoming_messages node.

uid_1 sends a message to uid_0, that message will have a key created with childByAutoId which will make it a unique message. uid_0 reads it and responds by posting a message to uid_1 incoming_messages node.

This is a basic example and there are 1000 different ways to do it so once you get this working, you can explore the space with other structures depending on your use case.

uid_0
   incoming_messages
    -Y999nsjnss8s
      msg: "hello to uid_0 from uid_1"
      from: "uid_1"

uid_1
   incoming_messages
    -Yu99jis9jms
      msg: "this is uid_0 responding to uid_1 message"
      from: "uid_0