-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c93c7e
commit 8467c45
Showing
14 changed files
with
2,503 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "the-heart-center-app" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"flutter": { | ||
"platforms": { | ||
"android": { | ||
"default": { | ||
"projectId": "the-heart-center-app", | ||
"appId": "1:902613553839:android:b3cb24b376a4cfc264ba5a", | ||
"fileOutput": "android/app/google-services.json" | ||
} | ||
}, | ||
"ios": { | ||
"default": { | ||
"projectId": "the-heart-center-app", | ||
"appId": "1:902613553839:ios:4724e712e57cda2864ba5a", | ||
"uploadDebugSymbols": false, | ||
"fileOutput": "ios/Runner/GoogleService-Info.plist" | ||
} | ||
}, | ||
"macos": { | ||
"default": { | ||
"projectId": "the-heart-center-app", | ||
"appId": "1:902613553839:ios:4724e712e57cda2864ba5a", | ||
"uploadDebugSymbols": false, | ||
"fileOutput": "macos/Runner/GoogleService-Info.plist" | ||
} | ||
} | ||
} | ||
}, | ||
"functions": [ | ||
{ | ||
"source": "functions", | ||
"codebase": "default", | ||
"ignore": [ | ||
"node_modules", | ||
".git", | ||
"firebase-debug.log", | ||
"firebase-debug.*.log" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Import function triggers from their respective submodules: | ||
* | ||
* const {onCall} = require("firebase-functions/v2/https"); | ||
* const {onDocumentWritten} = require("firebase-functions/v2/firestore"); | ||
* | ||
* See a full list of supported triggers at https://firebase.google.com/docs/functions | ||
*/ | ||
|
||
const functions = require('firebase-functions'); | ||
const admin = require('firebase-admin'); | ||
admin.initializeApp(); | ||
const db = admin.firestore(); | ||
|
||
// Create and deploy your first functions | ||
// https://firebase.google.com/docs/functions/get-started | ||
|
||
exports.sendEventNotifications = functions.pubsub.schedule('every 10 minutes').onRun(async (context) => { | ||
const now = admin.firestore.Timestamp.now(); | ||
const oneHourLater = new Date(now.toDate().getTime() + 60 * 60 * 1000); | ||
const eventsRef = db.collection('scheduled_streams'); | ||
|
||
const snapshot = await eventsRef | ||
.where('date', '<=', oneHourLater) | ||
.where('date', '>=', now) | ||
.get(); | ||
|
||
if (snapshot.empty) { | ||
console.log('No upcoming events found'); | ||
return null; | ||
} | ||
|
||
const messages = []; | ||
snapshot.forEach(async doc => { | ||
const event = doc.data(); | ||
const eventId = doc.id; | ||
const signupsRef = eventsRef.doc(eventId).collection('signups'); | ||
const signupSnapshot = await signupsRef.get(); | ||
|
||
if(!signupSnapshot.empty){ | ||
signupSnapshot.forEach(async userDoc => { | ||
const signupData = userDoc.data(); | ||
const notified = signupData.notified; | ||
const signupId = userDoc.id; | ||
const userRef = db.collection('users').doc(signupId); | ||
const userSnapshot = await userRef.get(); | ||
if (!userSnapshot.empty) { | ||
const fcmToken = userSnapshot.data().fcmToken; | ||
const notify = userSnapshot.data().notify; | ||
if (fcmToken && notify === true && (notified === false || notified === undefined)) { | ||
const message = { | ||
notification: { | ||
title: event.title, | ||
body: `Your event is starting in 1 hour!`, | ||
}, | ||
token: fcmToken, | ||
}; | ||
messages.push(admin.messaging().send(message)); | ||
} | ||
await signupsRef.doc(signupId).update({ | ||
notified: true | ||
}); | ||
} else { | ||
console.log("No such user found!"); | ||
} | ||
}); | ||
|
||
} else { | ||
console.log('No Signups found'); | ||
return null; | ||
} | ||
|
||
}); | ||
|
||
try { | ||
const response = await admin.messaging().send(message); | ||
console.log('Successfully sent message:', response); | ||
} catch (error) { | ||
console.log('Error sending message:', error); | ||
} | ||
return null; | ||
}); |
Oops, something went wrong.