diff options
| author | stone <jules+okfprojz@okfoc.us> | 2017-02-18 22:52:02 -0500 |
|---|---|---|
| committer | stone <jules+okfprojz@okfoc.us> | 2017-02-18 22:52:02 -0500 |
| commit | b7fbbf3f91490a488e54fe5f8c700813f0ab8021 (patch) | |
| tree | ea4335ca74f52be11b96102e473552335aecbdc1 /lib | |
| parent | 028e52fac9df2440a839e53a6b8bb7fdbc6f0ecd (diff) | |
pushing the push notifications
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/okpush/apn.js | 5 | ||||
| -rw-r--r-- | lib/okpush/db.js | 12 | ||||
| -rw-r--r-- | lib/okpush/index.js | 4 |
3 files changed, 16 insertions, 5 deletions
diff --git a/lib/okpush/apn.js b/lib/okpush/apn.js index 75322fae..14de7ac8 100644 --- a/lib/okpush/apn.js +++ b/lib/okpush/apn.js @@ -12,12 +12,13 @@ function init (config) { } function push (channel, note) { - db.getAllTokens(note, function(err, tokens){ + db.getAllIOSTokens(channel, function(err, tokens){ if (err) { console.error("Error fetching devices:", err) return } - connection.send(note, tokens).then( function (response) { + console.log(note, tokens) + apnProvider.send(note, tokens).then( function (response) { // response.sent.forEach( function (token) { // notificationSent(user, token) // }) diff --git a/lib/okpush/db.js b/lib/okpush/db.js index 563df18e..8c92753a 100644 --- a/lib/okpush/db.js +++ b/lib/okpush/db.js @@ -65,6 +65,15 @@ function errorHandler (error) { function addToken (data) { return new PushToken(data).save() } +function getAllIOSTokens (channel, cb) { + PushToken.find({ channel: channel, platform: 'ios' }, function (err, items) { + if (err) return cb(err, null) + var items = _.map(items, function (item) { + return item.token + }) + return cb(null, items) + }) +} function getAllTokens (channel, cb) { PushToken.find({ channel: channel }, function (err, items) { if (err) return cb(err, null) @@ -134,7 +143,8 @@ module.exports = { addToken: addToken, removeToken: removeToken, getAllTokens: getAllTokens, + getAllIOSTokens: getAllIOSTokens, getDeviceCount: getDeviceCount, addNotification: addNotification, getNotifications: getNotifications, -}
\ No newline at end of file +} diff --git a/lib/okpush/index.js b/lib/okpush/index.js index d696c350..36588aa2 100644 --- a/lib/okpush/index.js +++ b/lib/okpush/index.js @@ -103,8 +103,8 @@ function OKPush (options) { var opt = options.config.notifications[channel] var note = apn.buildPayload(opt, options.config.bundleId) apn.push(channel, note) - db.updateNotification(key, function(){ - res.send(200) + db.addNotification(channel, function(){ + res.sendStatus(200) }) }) |
