/** * Sends the weekly top post email to all users in the given `users` object. */ function sendWeeklyTopPostEmail(users, emailHtml) { Object.keys(users).forEach(function(uid) { const user = users[uid]; if (user.email) { const mailOptions = { from: '"Firebase Database Quickstart" <noreply@firebase.com>', to: user.email, subject: 'This week\'s top posts!', html: emailHtml }; mailTransport.sendMail(mailOptions).then(function() { console.log('Weekly top posts email sent to: ' + user.email); // Save the date at which we sent the weekly email. // [START basic_write] return firebase.database().ref().child('/users/' + uid + '/lastSentWeeklyTimestamp') .set(firebase.database.ServerValue.TIMESTAMP); // [END basic_write] }).catch(function(error) { console.log('Failed to send weekly top posts email:', error); }); } }); }
firebase.database.ServerValue.TIMESTAMP; update['/user-posts/' + uid + '/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; firebase.database().ref().update(update);
// [START single_value_read] function sendNotificationToUser(uid, postId) { // Fetch the user's email. var userRef = firebase.database().ref('/users/' + uid); userRef.once('value').then(function(snapshot) { var email = snapshot.val().email; // Send the email to the user. // [START_EXCLUDE] if (email) { console.log('entra al mail'); sendNotificationEmail(email).then(function() { // Save the date at which we sent that notification. // [START write_fan_out] var update = {}; update['/posts/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; update['/user-posts/' + uid + '/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; firebase.database().ref().update(update); // [END write_fan_out] }); } // [END_EXCLUDE] }).catch(function(error) { console.log('Failed to send notification to user:', error); }); }
/** * Sends the weekly top post email to all users in the given `users` object. */ function sendWeeklyTopPostEmail(users, emailHtml) { Object.keys(users).forEach(function(uid) { var user = users[uid]; if (user.email) { var mailOptions = { from: '"Firebase Database Quickstart" <noreply@firebase.com>', to: user.email, subject: 'This week\'s top posts!', html: emailHtml }; mailTransport.sendMail(mailOptions).then(function() { console.log('Weekly top posts email sent to: ' + user.email); // Save the date at which we sent the weekly email. // [START basic_write] return firebase.database().child('/users/' + uid + '/lastSentWeeklyTimestamp') .set(firebase.database.ServerValue.TIMESTAMP); // [END basic_write] }).catch(function(error) { console.log('Failed to send weekly top posts email:', error); }); } }); }
/** * Sends the weekly top post email to all users in the given `users` object. */ function sendWeeklyTopPostEmail(users, emailHtml) { Object.keys(users).forEach(function(uid) { const user = users[uid]; if (user.email) { const mailOptions = { from: '"Firebase Database Quickstart" <noreply@firebase.com>', to: user.email, subject: 'This week\'s top posts!', html: emailHtml }; mailTransport.sendMail(mailOptions).then(function() { console.log('Weekly top posts email sent to: ' + user.email); // Save the date at which we sent the weekly email. // [START basic_write] return firebase.database().ref().child('/users/' + uid + '/lastSentWeeklyTimestamp') .set(firebase.database.ServerValue.TIMESTAMP); // [END basic_write] }).catch(function(error) { console.log('Failed to send weekly top posts email:', error); }); } }); }
firebase.database.ServerValue.TIMESTAMP; update['/user-posts/' + uid + '/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; firebase.database().ref().update(update);