Skip to content
Permalink
d5e5386e1a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
29 lines (24 sloc) 867 Bytes
function saveMessageToFirebase(msg) {
db.collection("messages").add(msg)
}
function getAllMessagesFromFirebase() {
let allMsgs = [];
db.collection("messages").orderBy('dateStamp', 'asc').limit(200).get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
allMsgs.push(doc.data())
});
});
return allMsgs;
}
function watchFirebaseForChanges(callBack) {
db.collection("messages").orderBy('dateStamp','asc').onSnapshot(function(querySnapshot) {
querySnapshot.docChanges().forEach(function(change) {
if (change.type === "added") {
callBack(change.doc);
}
});
});
}
//getAllMessagesFromFirebase();
//watchFirebaseForChanges(function(msg){displayNewMessage(msg.data())})