diff --git a/firebase/functions/index.js b/firebase/functions/index.js index 475f6d8..292b51c 100644 --- a/firebase/functions/index.js +++ b/firebase/functions/index.js @@ -18,7 +18,12 @@ exports.sendNotificationOnEventCreation = functions.firestore .document('Events/{eventId}') .onCreate(async (snapshot, context) => { const eventData = snapshot.data(); - const {familyId, creatorId} = eventData; + const {familyId, creatorId, email} = eventData; + + if (email) { + console.log('Event has an email field. Skipping notification.'); + return; + } if (!familyId || !creatorId) { console.error('Missing familyId or creatorId in event data'); @@ -33,14 +38,12 @@ exports.sendNotificationOnEventCreation = functions.firestore } } - // Increment event count for debouncing eventCount++; if (notificationTimeout) { - clearTimeout(notificationTimeout); // Reset the timer if events keep coming + clearTimeout(notificationTimeout); } - // Set a debounce time (e.g., 5 seconds) notificationTimeout = setTimeout(async () => { const eventMessage = eventCount === 1 ? `An event "${eventData.title}" has been added. Check it out!` @@ -88,7 +91,7 @@ exports.sendNotificationOnEventCreation = functions.firestore eventCount = 0; // Reset the event count after sending notification pushTokens = []; // Reset push tokens for the next round - }, 5000); // Debounce time (5 seconds) + }, 5000); });