Firebase connection
zeckdude opened this issue · comments
Hi there,
Great work! But I have some questions please:
Where in your code are you connecting to firebase? I don't see any API key or any connection code such as firebase.initializeApp(firebaseConfig)
.
Also, where are you adding the friends list? Can we see an example of the collection structure in your Realtime DB?
Since I am using react-native-firebase
google-services.json. You can follow it here: rn-firebase.
The Database is being used by other projects too, so a clustered structure:
Ah, I haven't used react-native-firebase
. I'll need to look into that.
As for the database structure, do you mind showing me the expanded messages
, friends
, and chat
collections? It will really help me understand how it all fits together. I think it may be good to talk about that in the videos too.
I noticed that the friends
collection is on the root. I'm not sure how it is structured right now, but wouldn't it make more sense to put the friends
collection as a property for each user?
Sure. But I just created the `friends database to push as in Register and then get the value from FriendList and then create a chat ID in Chat
The storing is a very bad practice but I've kept it open as it's just a pet tutorial project
This is so helpful! Thanks so much! What exactly about the storing is bad practice? What do you mean by "storing"?
As you see, I can see the text messages quite visibly, so can any user with the firebaseConfig
Yeah, but once the firebase config is secret, only the database owner will have access to those messages and that doesn't seem like a bad thing.
One thing I'm noticing is that the chats seem to be only for two persons, based on the key of the chat entry. If I want to make a chat room that is for 3 people, would I need to include the uid
for all 3 users in the key?
The is a global chatroom also, think in chat
reference, where anyone on pressing a button will connect to 1 database thus, chatroom
Yeah, the chatroom is a global chat where everyone can talk to everyone, but I'm referring to a chatroom for specific users. So only 3 people for example.
You can apply the same 2 people approach chat and nested if-condition by comparing the uid. Should work
So for 3 people it would be <uid>-<uid>-<uid>
? Do you know if there is a maximum amount of characters for a firebase object key? If the chat ends up being 6 people for example, that name will get very long.
When you are on group chat on any social media, you enter the chat-group name right? Just allow users to enter the chat group name, if it has not been created, it will be created and you enter, and if it has been, you directly enter the group-chat. Just create the database as per user entered
Yeah that makes sense. And I definitely see that working. My concern is that if there are many people in the chat, then the key for the chat log could potentially be like this:
OndwhXaYi7SJFtKAwpxXCK6vQTg1-5N6oKQcIlRfIXgVUA9Nt1xi0Npr2-jX0PGbS4RKMwLko6sE2jJUPyJ9Q2-5N6oKQcIlRfIXgVUA9Nt1xi0Npr2-Ndfsdsfknsfmnsfkjsdf45mknassda3-7asdkabnsdksdcghkenfvsivkejb2
If there are many people in the chat, the key will be restricted to 768 bytes (approximately 500-700 characters), which is around 22 people. Beyond that, it won't allow any more characters. I'm wondering if there's another way to associate users with a particular chat without putting it in the key.
Take the initial 5-10 characters, doubt it'll be same unless you are building for a large audience