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

198
Visualizações
React native firebase group messages by timestamp

I'm trying to group messages by timestamp, just like how whatsApp does, I'm using firestore db for storing messages and my message schema is as follows:

interface MessageType {
    id: string;
    roomId: string;
    text: string;
    sentBy: string;
    createdAt: Timestamp;
    user: User;
}

I tried the following and I did get slightly what I needed but there are some issues, I have shared a link to the chat screen, there you can see what is happening, when I enter the chat room, they appear for like a millisecond and disappears, then if I hit ctrl+s, then the timestamp appears but they render in wrong place (they should render at top, but they are rendering at bottom of last message of that particular day, as I'm using inverted prop in Flatlist), also, when I hit ctrl+s (notice rendering... at bottom) the last message (cmoooon) disappears as you can see in the video!

const ChatScreen = () => {
  const dates = new Set();
  const [messages, setMessages] = useState([]);
  ...
  return <FlatList
            inverted
            data={[...messages].reverse()}
            keyExtractor={(item: MessageType) => item.id}
            renderItem={({ item }) => renderItem({ item, user, dates })}
          />
}

const renderItem = ({item, user, dates}) => {
    const isSameDate = dates.has(item?.createdAt?.toDate().toDateString());
    if (!isSameDate) {
        dates.add(item?.createdAt?.toDate().toDateString());
        return <DateItem time={item?.createdAt?.toDate().toDateString()} />
    }
    return <MessageItem data={item} key={item.id} myId={user.uid} />;
};

Video link: https://drive.google.com/file/d/1_h5742ObC9rBOqvBCZgrhJV9vWK1b9xz/view?usp=sharing

Can someone help me with this?

about 4 years ago · Juan Pablo Isaza
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