mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 17:47:08 +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}')
|
.document('Events/{eventId}')
|
||||||
.onCreate(async (snapshot, context) => {
|
.onCreate(async (snapshot, context) => {
|
||||||
const eventData = snapshot.data();
|
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) {
|
if (!familyId || !creatorId) {
|
||||||
console.error('Missing familyId or creatorId in event data');
|
console.error('Missing familyId or creatorId in event data');
|
||||||
@ -33,14 +38,12 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment event count for debouncing
|
|
||||||
eventCount++;
|
eventCount++;
|
||||||
|
|
||||||
if (notificationTimeout) {
|
if (notificationTimeout) {
|
||||||
clearTimeout(notificationTimeout); // Reset the timer if events keep coming
|
clearTimeout(notificationTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a debounce time (e.g., 5 seconds)
|
|
||||||
notificationTimeout = setTimeout(async () => {
|
notificationTimeout = setTimeout(async () => {
|
||||||
const eventMessage = eventCount === 1
|
const eventMessage = eventCount === 1
|
||||||
? `An event "${eventData.title}" has been added. Check it out!`
|
? `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
|
eventCount = 0; // Reset the event count after sending notification
|
||||||
pushTokens = []; // Reset push tokens for the next round
|
pushTokens = []; // Reset push tokens for the next round
|
||||||
|
|
||||||
}, 5000); // Debounce time (5 seconds)
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user