# Firebase Tutorial: Real-time Chat

**URL:** <https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379>\
**Category:** 🎓 Courses & Articles\
**Created:** [August 1, 2018, 1:01pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379 "2018-08-01T13:01:22Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [October 1, 2018, 3:40pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/63 "2018-10-01T15:40:56Z")

</div>

I’m glad you liked the tutorial!

It certainly is possible to send audio. You would need a method of recording audio first, then you’d save that audio input to Firebase Storage and add it to a custom audio message like the photo message.

Deleting a message from the chat view is also doable. You’d need to validate if the current user can delete a specific message, delete it from Firestore, then listen for the document change and remove it from the view.

---

<div class="post-metadata">

**Author:** ![qasimsqm](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/qasimsqm/32/78303_2.png) [@qasimsqm](https://forums.kodeco.com/u/qasimsqm)\
**Post date:** [October 20, 2018, 4:40pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/64 "2018-10-20T16:40:34Z")

</div>

Now how we can show typing indicator in the chat?

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [October 30, 2018, 11:31pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/65 "2018-10-30T23:31:30Z")

</div>

@naturaln0va Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![awaisfayyazbp](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/awaisfayyazbp/32/108688_2.png) [@awaisfayyazbp](https://forums.kodeco.com/u/awaisfayyazbp)\
**Post date:** [October 31, 2018, 12:31pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/66 "2018-10-31T12:31:52Z")

</div>

Hi, Great tutorial,

Can you tell me how you find out that the documentation exists at [https://messagekit.github.io/](https://messagekit.github.io/)

Its not mentioned in the repo. Is documentation available for every repo out there ?

Thanks

---

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [October 31, 2018, 5:22pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/67 "2018-10-31T17:22:48Z")

</div>

You can still achieve feature this using the new Firestore technology.

One way this could be done is by adding another top level collection in the Firestore database. This new top level collection would contain sub-collections referenced by the thread identifier from the channels top level collection.

Inside the sub-collection referenced by the thread identifier you would associate a user’s identifier with the **last date** that they typed.

Then the client app would check if there were any **recent** user’s that typed and update the indicator accordingly.

This is one way of doing it, I hope that can help get you pointed in the right direction!

---

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [October 31, 2018, 5:22pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/68 "2018-10-31T17:22:56Z")

</div>

Thanks, I’m glad you liked it.

I found MessageKit’s documentation website at the very top of their GitHub page. It’s up to each repo’s author to document their project or not. It would be nice, but there isn’t always documentation for every open source repository out there.

---

<div class="post-metadata">

**Author:** ![rickhindriksen](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rickhindriksen/32/78846_2.png) [@rickhindriksen](https://forums.kodeco.com/u/rickhindriksen)\
**Post date:** [November 10, 2018, 11:06pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/69 "2018-11-10T23:06:42Z")

</div>

Amazing tutorial. I’ve learned a lot! Thanks. 😀

---

<div class="post-metadata">

**Author:** ![floryan2oo7](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/floryan2oo7/32/81494_2.png) [@floryan2oo7](https://forums.kodeco.com/u/floryan2oo7)\
**Post date:** [November 10, 2018, 11:49pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/70 "2018-11-10T23:49:10Z")

</div>

Thanks so much for the tutorial! I’ve created and open-sourced a [Facebook Messenger clone](https://www.instamobile.io/app-templates/ios-chat-app-swift-firebase-download/) based on your approach.

---

<div class="post-metadata">

**Author:** ![shap](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@shap](https://forums.kodeco.com/u/shap)\
**Post date:** [November 26, 2018, 3:57pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/71 "2018-11-26T15:57:06Z")

</div>

Hello.

I am trying to intergrade part of your sample app into an application i have built however it seems mine fails to go past the loginviewcontroller. It seems to be authenticating however the view doesnt transition to the channelesview controller. In my app i have already done the authentication though firebase earlier so i just need your app to use the same user and proceed to the channelesviewcontroller. Unfortunately right now when i type in a screen name in your login page of your app, it does not proceed to channeles. I can confirm that the sign in process does happen. Can you help me effectively tell your app that the user is signed in and to proceed to the channelesview controller?

Your help is greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![shap](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@shap](https://forums.kodeco.com/u/shap)\
**Post date:** [November 27, 2018, 7:28am UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/72 "2018-11-27T07:28:32Z")

</div>

I have narrowed it down now and have a more specific question regarding this.

I understand a Notification.default.addobserver is used int the Appcontroller to handel the authstatedidchange.

As my auth state is not changing in the loginviewcontroller (the user already logged in earler in my app) i would need to modify this code so it is not looking for an authstate change thus pushing the view forward to channelsviewcontroller. Could anyone help me modify this observer to atchive this. Any ideas would be very helpful. Thanks!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 27, 2018, 1:50pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/73 "2018-11-27T13:50:07Z")

</div>

@naturaln0va Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [November 27, 2018, 4:20pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/74 "2018-11-27T16:20:50Z")

</div>

The sample app was designed to show the `LoginViewController` as the root view of the app for a user that isn’t signed in yet. So handling the authentication change state in **AppController** is preferred.

If you want to push the **ChannelsViewController** from the **LoginViewController** just push it on the navigation controller like so:

```swift
let vc = ChannelsViewController()
navigationController?.pushViewController(vc, animated: true)

```

I’m not sure what you want to accomplish, so I hope that helps.

---

<div class="post-metadata">

**Author:** ![shap](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@shap](https://forums.kodeco.com/u/shap)\
**Post date:** [November 27, 2018, 8:08pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/75 "2018-11-27T20:08:27Z")

</div>

Hello. Thank you very much for your reply.

I am coming from a view controller that i have created which does the user authentication itself. So when the user navigates to the chat app within my application inputs screen name and hits “get started” the screen does not move to the channelsviewcontroller becuse its not detecting a new auth.

I am attempting to keep the user logged in at this point and tell the app controller to proceed to the next page but all the appcontroller wants is to detect a new auth before sending the user to the channelsview controller. How do i change this logic to archive this? Thanks!

---

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [November 27, 2018, 10:51pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/76 "2018-11-27T22:51:45Z")

</div>

You shouldn’t be using the **AppController** in that way, it wasn’t ever intended for your use case. I would incorporate the screen name into your sign in mechanism. Then just take the user to the **ChannelsViewController**. The only thing you need is the Firebase user model for the **ChannelsViewController** to work properly. If you’re signing into your app using **Firebase** just use `Auth.auth().currentUser`.

---

<div class="post-metadata">

**Author:** ![shap](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@shap](https://forums.kodeco.com/u/shap)\
**Post date:** [November 27, 2018, 11:34pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/77 "2018-11-27T23:34:57Z")

</div>

Ok. So to confirm, the only thing App Controller does in this case is handel the appstate upon logging in. In other words if i eliminate the App Controller and take your suggested approach, the rest of the chat app should work as intended?

Thanks!

---

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [November 28, 2018, 5:14am UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/78 "2018-11-28T05:14:50Z")

</div>

Yes. The **AppController** only manages the root views based on the current authentication state.

You should only need **ChatViewController** and **ChannelsViewController** for the chat features to work in your app.

I’m sorry this wan’t clear in the tutorial.

---

<div class="post-metadata">

**Author:** ![shap](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@shap](https://forums.kodeco.com/u/shap)\
**Post date:** [November 28, 2018, 6:26am UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/79 "2018-11-28T06:26:18Z")

</div>

Got it! Thank you man. Yourself and this website have been a great resource!

---

<div class="post-metadata">

**Author:** ![marcuskirsch](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marcuskirsch/32/78996_2.png) [@marcuskirsch](https://forums.kodeco.com/u/marcuskirsch)\
**Post date:** [November 30, 2018, 9:13am UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/80 "2018-11-30T09:13:21Z")

</div>

WHere can I find the easiest way to invite other to a room? Right now I am having monologues… 🙂 Great tutorial, but as its a chat app, it woudl be great to add a link on how to add a second user to the chat.

---

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [November 30, 2018, 7:50pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/81 "2018-11-30T19:50:24Z")

</div>

You are very welcome!

---

<div class="post-metadata">

**Author:** ![naturaln0va](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naturaln0va/32/105148_2.png) [@naturaln0va](https://forums.kodeco.com/u/naturaln0va)\
**Post date:** [November 30, 2018, 7:57pm UTC](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379/82 "2018-11-30T19:57:57Z")

</div>

The idea for this tutorial was to create a IRC where other people would join the same channel to discuss stuff. So if you were to take this tutorial and build a full app out of it, you would invite users by telling them to join you in a channel for a given name, like “iOS Development”.

You can certainly take the basic concepts and apply them to a peer to peer chat application like iMessage. However that it’s in the scope of this tutorial and it would be more complex to explain all of the technical details behind that.

I will give you some high level advice though for building a peer to peer chat app. I would have an account sign up feature for my users. Then in the app I would make a search feature to find the person I want to message. After that I would start up a conversation that manages the messages from the 2 users.

I hope this helps.

[Previous page](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379.md?page=3)

[Next page](https://forums.kodeco.com/t/firebase-tutorial-real-time-chat/45379.md?page=5)
