This code is assigning the value of 'temps' to this.messages for some reason that I do not understand, any help would be appreciated. I know the issue lies within the below chunk of code as removing the .sort section changes the output order of this.messages.
this.currentMessageSubject.subscribe(()=> {
console.log('Refreshing messages')
if (this.conversationId) {
firebase.firestore().collectionGroup('conv').where("parentMessageId", "==", this.conversationId).get().then(async (querySnapshot) => {
let temps: FirebaseMessages;
let tempsMsgs = new Map();
temps = this.messages;
temps.messages = []
querySnapshot.forEach((newConvo) => {
const thing = { id: newConvo.id, ...newConvo.data() } as FirebaseMessage;
if (!tempsMsgs.has(thing.id)) {
tempsMsgs.set(thing.id, thing)
temps.messages.push(thing);
}
})
temps.messages.sort(function(a,b){
return a.timestamp.seconds - b.timestamp.seconds;
});
temps.messages = temps.messages.filter((message) => {
if (message.id) {
return true;
}
return false;
})
})
}
})