MCPcopy Create free account
hub / github.com/firebase/codelab-friendlychat-web / loadMessages

Function loadMessages

appcheck/hosting/src/index.js:122–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

120
121 // Loads chat messages history and listens for upcoming ones.
122 function loadMessages() {
123 // Create the query to load the last 12 messages and listen for new ones.
124 const recentMessagesQuery = query(collection(getFirestore(), 'messages'), orderBy('timestamp', 'desc'), limit(12));
125
126 // Start listening to the query.
127 onSnapshot(recentMessagesQuery, function(snapshot) {
128 snapshot.docChanges().forEach(function(change) {
129 if (change.type === 'removed') {
130 deleteMessage(change.doc.id);
131 } else {
132 var message = change.doc.data();
133 displayMessage(change.doc.id, message.timestamp, message.name,
134 message.text, message.profilePicUrl, message.imageUrl);
135 }
136 });
137 });
138 }
139
140 // Saves a new message containing an image in Firebase.
141 // This first saves the image in Firebase storage.

Callers 1

index.jsFile · 0.70

Calls 2

deleteMessageFunction · 0.70
displayMessageFunction · 0.70

Tested by

no test coverage detected