Skip to content

Instantly share code, notes, and snippets.

@Bashta
Last active May 25, 2016 11:55
Show Gist options
  • Save Bashta/f2d5d6c4e68012186fb4c226d6842167 to your computer and use it in GitHub Desktop.
Save Bashta/f2d5d6c4e68012186fb4c226d6842167 to your computer and use it in GitHub Desktop.
Parse.Cloud.job("incomingEventNotification", function () {
Parse.Cloud.useMasterKey();
var query = new Parse.Query("Event");
query.greaterThan("limit", 1);
query.equalTo("notifiedAboutUpcomingEvent", false);
query.find().then(function(results) {
//get the event
for (var event in results) {
for (var userID in event.object.get("attendeeIDs")) {
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('channels', userID);
var eventName = event.object.get("summary");
Parse.Push.send({
where: pushQuery,
data: {
alert: eventName + ", " + "starting in 24 hours"
},
}, {
success: function (success) {
// Push was successful
event.set("notifiedAboutUpcomingEvent", true)
event.save()
},
error: function (error) {
throw "Got an error " + error.code + " : " + error.message;
}
}
}
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment