summaryrefslogtreecommitdiff
path: root/examples/lib/okpush/apn.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-10-06 13:20:23 -0400
committerJules Laplace <jules@okfoc.us>2016-10-06 13:20:23 -0400
commitf8bbee2634329595711d33ae82923f23a3ddb7fc (patch)
tree50aedcdc2006eda324b59f8eaeb831fc13fd6eac /examples/lib/okpush/apn.js
parentef2cfac2c055cdfa3958374c68a8d0cfe4e4f046 (diff)
store notification last update in db
Diffstat (limited to 'examples/lib/okpush/apn.js')
-rw-r--r--examples/lib/okpush/apn.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/examples/lib/okpush/apn.js b/examples/lib/okpush/apn.js
index 5e13e15..b6909f6 100644
--- a/examples/lib/okpush/apn.js
+++ b/examples/lib/okpush/apn.js
@@ -9,17 +9,21 @@ function init (config) {
apnProvider = new apn.Provider(config.apn.connection)
}
-function push (tokens, note) {
- tokens.forEach(function(token){
- connection.send(note, token).then( function (response) {
- response.sent.forEach( function (token) {
- // notificationSent(user, token)
- })
+function push (note) {
+ db.getAllDevices(function(err, tokens){
+ if (err) {
+ console.error("Error fetching devices:", err)
+ return
+ }
+ connection.send(note, tokens).then( function (response) {
+ // response.sent.forEach( function (token) {
+ // notificationSent(user, token)
+ // })
response.failed.forEach( function (failure) {
if (failure.error) {
// A transport-level error occurred (e.g. network problem)
// notificationError(user, token, failure.error);
- } else {
+ } else if (failure.status == 410) {
// `failure.status` is the HTTP status code
// `failure.response` is the JSON payload
// notificationFailed(token, failure.status, failure.response);