getMessagesStream method
this will the message stream
Implementation
Stream<List<DocumentSnapshot>> getMessagesStream() {
customPrint('The current message length is ${offlineMessages.length}');
if (offlineMessages.isNotEmpty) {
customPrint('The message stream id is $chatId');
return chatCollectionReference
.doc(chatId)
.collection(ApiKeys.messages)
// .where(ApiKeys.visibleTo, arrayContains: currentUserId)
.where(
ApiKeys.createdAt,
isGreaterThan: offlineMessages.first.createdAt,
)
.orderBy(ApiKeys.createdAt, descending: false)
.snapshots()
.map((snapshot) => snapshot.docs);
} else {
customPrint('The message stream id is $chatId');
return chatCollectionReference
.doc(chatId)
.collection('messages')
// .where("visibleTo", arrayContains: currentUserId)
.orderBy('createdAt', descending: false)
.snapshots()
.map((snapshot) => snapshot.docs);
}
}