Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
Firebase chat in React native : How to get all registered users and users I've chatted with?

I am using firestore for my chat application

I have 2 tabs, first one is for to display all registered users and another second tab to display all users I've chatted with.

i have created 2 collections in firestore

  1. users : to store all registered users
  2. chatrooms : to store all messages of particular user

enter image description here

i have combined 2 users id to identify sender and receiver and stored it in messages.

Code:

1. //get all registered users
const querySanp = await firestore()
  .collection('users')
  .where('uid', '!=', user.uid)
  .get();
const allusers = querySanp.docs.map(docSnap => docSnap.data());
setUsers(allusers);

2. //get all registered users
 const docid = uid > user.uid ? user.uid + '-' + uid : uid + '-' + user.uid;

const messageRef = firestore()
  .collection('chatrooms')
  .doc(docid)
  .collection('messages')
  .orderBy('createdAt', 'desc');

const unSubscribe = messageRef.onSnapshot(querySnap => {
  const allmsg = querySnap.docs.map(docSanp => {
    const data = docSanp.data();
    if (data.createdAt) {
      return {
        ...docSanp.data(),
        createdAt: docSanp.data().createdAt.toDate(),
      };
    } else {
      return {
        ...docSanp.data(),
        createdAt: new Date(),
      };
    }
  });
  setMessages(allmsg);
});

How to get users i have chat with ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can create a collection :

Conversations: {
   user1,
   user2
}

And in your messages collection:

messages : {
  conversationId,
  sender,
  receiver
}

So you in your app (I suppose you have a screen chats), you just get all the conversations where you are user1 or user2.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda