Hi I am trying to listen to new chat messages (when someone or I add new chat message) like below. but its not listening to live queries. Please help me to sort it ...
async componentDidMount() {
this.getChatTexts();
}
async getChatTexts() {
if (this.state.tripId) {
firestore()
.collection('Chats')
.where('tripId', '==', this.state.tripId)
.orderBy('time', 'desc')
.onSnapshot({includeMetadataChanges: true}, snapshot => {
if (snapshot) {
this.setState({chatWindow: true});
var chatmessages = [];
snapshot.docChanges().forEach(e => {
chatmessages.push(e.doc.data());
});
this.setState({chatMessages: chatmessages});
}
});
}
}