Flutter : open a chat room for 2 users based on condition - firebase

hello I am building a chat app with firebase , and I already know how to make the chat room and make users chat with each other .
in my app i have a Cupertino picker which have some values , what iam looking for is
1 - if 2 users have selected the same value a chat room document will be created and both of them will chat with each other , what are the possible solutions for that ? .
2 - notifications based on topic that are dynamic should be by using cloud functions and typescript with onCreate method right ?

1 - you could do something like creating an object like this
users_waiting_for_connection -> user_id, selected_value, creation_time, ...
So when a user pick a value you check for elements in the list for the same selected_value.. if found you create the room and delete the object from the list, if not found you create the element in the list
2 - yup, you can find any info in the documentation
https://firebase.flutter.dev/docs/functions/overview/

Related

How to retrieve child nodes data in firebase by php

How to retrieve child nodes data and update values in firebase:
As I want to make an API in which I create parameters to pass values by it.
Like example I have one node in firebase name as users and under it has user amount is 10. I want to get that data of amount from users node and add some value with it like 10+5 will update in database as 15 in my firebase.
I tried to retrieve data from firebase by seeing youtube, but I'm unable to get what I want; I was only able to get the whole users node data at whole.
That sounds like a 2-step process:
Store the value as a number rather than as a string like you now have it.
Then use the atomic increment operation to increment it by 5.

Flutter: How to send notifications to users when a document with specific field values is created. (how to subscribe to topic with condition)

I want to add a "Notify me" function in my flutter app where the user enters a date and other values so when a document is created with those values, the user can get a notification. I'm unable to add any conditions in fcm.subscribeToTopic();.TIA.
You can create a cloud function and deploy it to firebase Functions, and in that function specify the path of collection (in which your document is creating) and it will trigger when a new document is created (write function for that. example ). in order to send notifications to that user store that user's device Token. you can find cloud Firestore Functions here.
some articles that help: firebase tiggers
Subscriptions to a topic are unconditional. The simplest way I can think of to implement this use-case is to create topics that contain the specific conditions that you are interested in, like date_20210823_value_yourvalue.

How can i retrieve a document using specific field in firestore

Hello guys , how can i get all information inside this Document with using the field [ ID ] , i tried to use the where Query but i couldn't success with that
I assume you wanna do this on the firebase website. Let me show you how I did this using my collection.
Step 1: Go to Filter by field, then select the field you want
Step 2: Add condition which should be "(==) equal to"
Step 3: Click on Apply
Voila! Now you can retrieve a document using a specific field in firestore.
Anyhow, if you want to retrieve a document using a specific field inside a frontend code. Then it would be a bit different depending on the language or framework you use.

How to give 1 firebase id to 2 users in flutter?

I'm trying to make chat app in flutter using firebase. And i want to know, can i make chat using users id? I mean chatID=user1ID+user2ID, is it possible?
I think you can add a field of type array to your chat document and name it as chat _user and just pass the two users ids to it as like this =>

Custom Authentication in Google Firebase

I have a question regarding authentication using Google Firebase.
For an app, I want to build an authentication similar to the one Slack uses: first, the user provides the input as to which group they want to log in to. If there exists a group with the same name as provided in the input, the user is then taken to a login/signup screen.
I've thought about storing users in the realtime database as follows, but I think there must be a better way to do this (since I don't think I can use the firebase authentication in this case):
groups: {
"some_group_name": {
"users": [
"user1": {
.. user 1 information
},
"user2": {
.. user 2 information
}
],
"group_details": {
"name": ..,
"someGroupDetail": ..
}
},
"some_other_group_name": {
...
}
}
I haven't realized if there is an obvious answer yet, so I'm open to suggestions. How would you suggest I tackle this?
Thanks
PS: I'm building the application using Nativescript and Angular, and (so far) there is no server or database involved other than Firebase.
Another suggestion that might work, is by using Firebase Auth Custom Claims. That way, you only need to store the group ID and group name in your realtime database, without worrying to keep changing the database each time user is added or removed.
This is one way you can do it:
Store database exactly like you have it, with it's group ID and name.
In your backend script (I recommend Cloud Function), each time a User is registering themselves, add custom claims in your user: Specifying what group is the User belong to.
Every time user authenticate, retrieve the group ID from custom claims. And there you get it!
Note: be careful not to put too much information in your custom claims as it cannot exceed 1000 bytes.
Read more about it here: https://firebase.google.com/docs/auth/admin/custom-claims
I would suggest you to implement Root-level collections.
Which is to create collections at the root level of your database to organize disparate data sets(as shown in the image below).
Advantages: As your lists grow, the size of the parent document doesn't change. You also get full query capabilities on
subcollections.
Possible use case: In the same chat app, for example, you
might create collections of users or messages within chat room
documents
Based on the reference from the firebase cloud firestore
Choose a data structure tutorial (I know you are using Realtime database but structuring the database is the same since both are using the NoSQL Schema)
For your case:
Make 2 Collections: Users, Groups
Users: User info is stored in the form of document
Groups: In the Groups Collection, here comes the tricky part, you can either store all groups subcollection under 1 document or split into multiple documents (based on your preference)
In the group-subcollection, you can now store your group info as well as the user assigned where you can store user assigned in the form of array, therefore whenever a user access the group, query the user assigned first, if yes, then allow (assuming users can view all group)
You do the thinking now

Resources