mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00
send notifications only if the event has no email address
This commit is contained in:
@ -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);
|
||||
});
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user