How to know the count of repeated entries in Firestore flutter? - flutter

I'm creating a appointment app in flutter using firebase in which I have keep the track of people that got appointment repeatedly based on their phone number . How do I get this count of repeated entries?

it would be better if you add some code and more information to your question so we can can answer correctly but based on my understanding you want to check if this user repeatedly booked appointments using your app considering that it is a logged in user not a guest,
in this case inside your Firestore collection that contains the users i assume that each document represent a user add to each document (user information) a counter (integer variable) called for example "appointementsNumber" and every time a user book an appointment this counter will be increased by one, in this case you are able to know how many times this user booked an appointment.
hopefully i did understand your question correctly.

Related

How to Implement "Your contact just joined app" feature

I am building a mobile app (in flutter firebase, but the answer does not have to be firebase specific). And I would like to implement a feature that notifies users whenever anyone from their contact list joins the app. This seems like a very EXPENSIVE feature.
At the top of my head, I see a lambda/cloud function that is triggered everytime a user joins and then searches a database of users and their respective contacts for the existence of the new user's phone number. To me, this solution does not scale well for two reasons: if the number of total users is in the millions and the number of users joining simultaneously is a lot.
My better solution is to get the user's contacts upon joining and then searching a database of current users contacts for any of the phone numbers of the newly joined user.
Is there a solution better than the second one? If so, what is it? If the second solution is standard, what kind of backend storage mechanism provides the best search and retrieval time for a database of users and their respective contacts?
In the case of large users ill not do first solution because that may slow the sign up process instead i will creat a cron job that runs at a specific time or periodically it will get the list of the latest users signed up that day or that hour whatever you prefer then that cron will check the new user if related to any user in the databases and send a notification right away, or a better solution create a temporary table in a database in another server insert the notification informations into the other server, creat another cron job in the second server it will run at a specific time to sendthe notification

Flutter: How to implement random chat rooms with firebase?

I am currently trying to develop a random chat application which matches users randomly and allows them to chat and then add each other as friends (if they enjoyed the chat) in order to continue the chat.
So now I need to solve three problems:
match users randomly
My idea would be to implement a method which randomly picks two user ids from my users collection. But I do not know how to implement this in code - Can anybody help here?
craete a chat room to store the messages
This is the most difficult part. Currently my idea is to create a collection called "chats" and add a document which is named "$uid of user 1 & $uid of user2" where I save the messages. But I do not know how that would look in code and whether this actually solves the problem.
create a friend list
My idea is to create a list inside each user document and save the user ids of all friends. How could that be implemented in code? And is there a better solution to that?

Ban a User in a particular firebase firestore group chat for predefined time

I am very new to coding. but i managed to build a group chat app using a low code platform called flutterflow. i managed to spend significant amount of time on it and was able to build a public group chat app except few functionalities. I am hoping to find help from here. for the following questions.
I have chat mods appointed on a group level. like if you create a group, you are a founder and you can assign mods to that perticular group chat. now i want these mods to be able to ban a user in that particular group chat.
I have tried created a subcollection in groups called "banned user" and created two feilds. one is "banned users" document reference to users. and another is "banned_till" to record a time stamp until the user gets banned.
Problem with this is when i ban a user twice, it creates two documents in the user reference with the same user. and two documents has different "banned_till" times. which one it is supposed to pick?
i tried to do this and put a conditional visibility to the chat that "if current time is less than or equal to banned_till time" it wont let user type in the textfield to chat. but this is giving me gray screen.
I am very new to this. any help would be appreciated.
there is specific way to do so. you have to set custom logic. like save all banned users in a firebase database object with thier max time and procced next.

FIrestore chat rooms with bucketing

First i'd like to add that while this is a Firestore question, im open to hear suggestions about integrating an additional Google service.
The System
I have a chat feature in my application. Since there could be a very decent scale, I decided to have a limit to a chat group.
Chat groups are not created by users and should be created automatically by using some sort of an incrementing index (e.g: room_1, room_2, ...., room_n).
The limit on each chat group is 100 users at most.
So if I have 100k users online, I'd expect to have 1k groups (aka n=1000).
The Issues
How can I distribute users, upon signing in, to chat groups? (Lets say the strategy is to fill current rooms first, hence the 'bucketing' in the title)
Since users can close the app without pressing "quit" or something, I need the system to know to adjust
You can add a counter to the room document and increment/decrement it using by FieldValue.increment, here is an usage example in Javascript:
//when a user enter the room
db.collection('chat_rooms').doc('room_1').update({
userCount: firebase.firestore.FieldValue.increment(1)
});
//when a user quits the room
db.collection('chat_rooms').doc('room_1').update({
userCount: firebase.firestore.FieldValue.increment(-1)
});
Since FieldValue.increment() gets the current value of the counter you don't need to worry about racing conditions, which is good given that you expect to have a huge number of user so this will be constantly updated.
You can wrap this arround a check of the room counter and if the room is over the limit of users you set for rooms a new room can start being filled.
For your second question a bit more information is required, but assuming you are using android you can use the onAppBackgrounded function in the example provided in this community answer to call the update that decrements the counter in the chat room document if the app is backgrounded or closed by the user, as part of the "forcing" him out of the room.

What is the right way to keep the information between my bot and Facebook consistent?

From what I read in the Facebook Messenger documentation, there are a couple of callbacks that are triggered. The onReceivedAuthentication() as per documentation is called when a person taps on the "Send to Messenger" plugin. I want to save the person's firstName, lastName, picture and gender in my database. What if the person directly searches for our page and starts chatting with it? In that case, the above callback won't be triggered right? What if the user changes their name or picture on Facebook? How do I keep my database consistent with Facebook's data for each user?
Currently, I am updating the person's details in my database everytime the user greets my bot. I don't think that is a good strategy. Any suggestions are appreciated.
Just decide particular time limit like 1 hour or 24 hours or 1 week or as per your choice and when you store user's data from facebook by its graph API response,store one more field for that particular time of storing it either by timestamp or date and after that whenever you get message from user just compare that messages' timestamp with that field and if that difference is greater than that decided time limit then update users' data.
you can compare user's current message time as you are getting it in form of timestamp with every message
Hope this help you.