streamLatestMessages method

Stream<List<Message>> streamLatestMessages(
  1. String chatId
)

Streams the latest messages for a chat, limited to the initial limit.

Implementation

Stream<List<Message>> streamLatestMessages(String chatId) {
  return _firestore
      .collection('chats')
      .doc(chatId.log('chatId'))
      .collection('messages')
      .orderBy('timestamp', descending: true)
      .limit(initialLimit) // Stream the latest 20 messages
      .snapshots()
      .map((snapshot) => snapshot.docs
          .map((doc) => Message.fromMap(doc.data().log('doc')))
          .toList());
}