Firebase Tutorial: Real-time Chat

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.

Now how we can show typing indicator in the chat?

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

1 Like

Hi, Great tutorial,

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

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

Thanks

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!

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.

Amazing tutorial. Iā€™ve learned a lot! Thanks. :grinning:

Thanks so much for the tutorial! Iā€™ve created and open-sourced a Facebook Messenger clone based on your approach.

1 Like

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!

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!

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

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:

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

Iā€™m not sure what you want to accomplish, so I hope that helps.

1 Like

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!

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.

1 Like

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!

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.

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

1 Like

WHere can I find the easiest way to invite other to a room? Right now I am having monologuesā€¦ :slight_smile: 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.

You are very welcome!

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.