Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda