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

Function saveMessage

web/src/index.js:89–102  ·  view source on GitHub ↗
(messageText)

Source from the content-addressed store, hash-verified

87
88 // Saves a new message to Cloud Firestore.
89 async function saveMessage(messageText) {
90 // Add a new message entry to the Firebase database.
91 try {
92 await addDoc(collection(getFirestore(), 'messages'), {
93 name: getUserName(),
94 text: messageText,
95 profilePicUrl: getProfilePicUrl(),
96 timestamp: serverTimestamp()
97 });
98 }
99 catch(error) {
100 console.error('Error writing new message to Firebase Database', error);
101 }
102 }
103
104 // Loads chat messages history and listens for upcoming ones.
105 function loadMessages() {

Callers 1

onMessageFormSubmitFunction · 0.70

Calls 2

getUserNameFunction · 0.70
getProfilePicUrlFunction · 0.70

Tested by

no test coverage detected