I am currently developing a chat application which allows users to chat with another random user by clicking a button. I have added the following package to my app: https://docs.flyer.chat/flutter/firebase/firebase-usage
My database looks as follows:
collection: rooms
document: chatroom1
subcollection: messages
collection: users
document: uid1 (which then includes fields like username, gender etc.)
So now I do not know how to get two random users from my users collection and create a chat room for them, in order to allow them to chat. How can I code the matching? And how do I create a chatroom for each random match? Is there a simple way?
2
Answers
First You need to create a list of users(uid or the doc_id) like this
then when you are trying to start chat so you can select the opponent by using this method
so it is just a reference for you for getting randow user.
Hope you understand
There is no simple way to do this. You will need to query your users collection to get a list of all users. Then, you will need to randomly select two users from that list and create a chat room for them.