Firestore chat private and group - google-cloud-firestore

I have this chat structure for groups and private in real time, is there any way to structure to get the images and names of the people who chat? currently using UserIds I do a separate query to get it, but if someone changes their name or image it won't update.

You typically would start a RTDB listener for the nodes of the RTDB that contain the information for each of the users. Alternatively, you could copy all of the relevant user information into "current chats" and if a user changes their profile information you could also copy that new information into any "current chat" sessions.
In my app, I maintain user profile information in a profile collection in Firestore, and maintain the chat details in RTDB. So I have a realtime listener for the chat (RTDB) and a realtime listener for firestore.collection('profile').where('uid', 'in', arrayOfUserIDsInChat).
(Currently the way I have things, I am limited to the number of user profiles I can listen to ... in is limited to 10 ... but that is sufficient for my current requirements)

Related

how can one user modify a data in firestore which will not affect other user data in the app?

I am new to flutter(and coding),I don't know if I specified the question clearly but what I want is for when a user "Follows" or "subscribe" to a product it goes to a listview but it changing the data globally in firestore, so in every user's listview has the same data subscribed. I want make it personalized for that specific user only, other can change the data too which will only affect that specific user only,
think of it as ecommerce cart function where every user has different thing in the cart
I did make a collection for "product" but every user getting data from same collection and it changing globally.
how can I make common subscribed data personalized for each user which will not conflict with others data.
how can I make common subscribed data personalized for each user which will not conflict with others data.
Every Firebase user has an id, you can use the user's id and set/query documents based on that.
For example, to set the data:
.collection('bla').doc(USER_ID).set({"name": "John"})
and to retrieve the data based on the id:
final snapshot = await Firestore.instance
.collection('bla')
.doc(USER_ID)
.get();
See also
How to get the current user id from Firebase in Flutter

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

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.

check weather the user readed data or not in flutter using firestore

I was developing the chat app in flutter using firestore, the users successfully chat one-to-one. but I also want to send the notification to the user that someone sends him/her a message. For that I decided to use the cloud messaging service of firebase, but how can I check that the user read the message or not.
There is nothing built into Cloud Firestore to track which user has read a specific document already.
The two most common approaches that I know of are:
To track for each individual message and each individual user whether they have read it, so by keeping a list of the user IDs in each message document. While this potentially stores a lot of extra data, it is the most direct mapping of your use-case.
In most chat apps though, tracking of what messages each user has read is done as an "up to here". So if the user has read all messages up until a certain one or a certain time, the assumption is that they've also read all the messages before that one/moment.
For this model you can instead just keep a single document ID or timestamp for each user (i.e. readUpTo), instead of having to mark each message for each user that has read it. In your UI, you then determine whether to show each message as unread based on the message ID/timestamp compared to the timestamp of readUpTo.

Persisting cart Items on my e-commerce website

I'm planning on an e-commerce website and would like some help!
The functionality I want is that whenever a user logs in, I will use the user's email address to fetch from my MongoDB database to retrieve all of the user's cart information (what the user has put in his/her cart from last time). However, I worry that if the user accidentally closes their tab, or closes their window, and visits the website again, then I would need to fetch from my database again to get the cart items. My question is that would it be better to store the cart item on a local storage or session storage. And then, once the user goes to the checkout page, I then store all of the cart items back to database. In that way, I don't need to store to and retrieve from the database everytime the user adds an item to the cart.
I'm using React/MongoDB. This is my first time building a e-commerce website and I would like to know how other people usually handle this problem, and whether local storage, session storage, or there are other ways to handle this!