From 2e3218ddd0dd4cccf9038f1fc7b6565c7bad7595 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 19 Feb 2017 02:47:17 +0100 Subject: show accurate count --- lib/okpush/apn.js | 2 +- lib/okpush/db.js | 2 +- lib/okpush/index.js | 47 +++++++++++++++++++++++---------------- lib/okpush/templates/index.liquid | 2 +- 4 files changed, 31 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/okpush/apn.js b/lib/okpush/apn.js index febd03bb..7506e08b 100644 --- a/lib/okpush/apn.js +++ b/lib/okpush/apn.js @@ -12,7 +12,7 @@ function init (config) { } function push (note) { - db.getAllDevices(function(err, tokens){ + db.getAllTokens(note, function(err, tokens){ if (err) { console.error("Error fetching devices:", err) return diff --git a/lib/okpush/db.js b/lib/okpush/db.js index f64acf69..563df18e 100644 --- a/lib/okpush/db.js +++ b/lib/okpush/db.js @@ -69,7 +69,7 @@ function getAllTokens (channel, cb) { PushToken.find({ channel: channel }, function (err, items) { if (err) return cb(err, null) var items = _.map(items, function (item) { - return _.pick(item, ['type', 'token']) + return _.pick(item, ['platform', 'token']) }) return cb(null, items) }) diff --git a/lib/okpush/index.js b/lib/okpush/index.js index df9c8265..6de59ac5 100644 --- a/lib/okpush/index.js +++ b/lib/okpush/index.js @@ -50,23 +50,23 @@ function OKPush (options) { apn.init(config) db.init(config) -// router.use('/admin/', passport.initialize()) + router.use('/admin/', passport.initialize()) router.use('/public/', express.static(path.join(__dirname, './public'))); // monkeypatch because of app.use(router) .. obnoxious -// router.all('/admin/(:path*)?', function (req, res, next) { -// console.log(req.url) -// req.newUrl = req.url -// req.url = req.originalUrl -// next() -// }) -// router.all('/admin/(:path*)?', passport.authenticate('digest', { -// session: false -// })) -// router.all('/admin/(:path*)?', function (req, res, next) { -// req.url = req.newUrl -// next() -// }) + router.all('/admin/(:path*)?', function (req, res, next) { + console.log(req.url) + req.newUrl = req.url + req.url = req.originalUrl + next() + }) + router.all('/admin/(:path*)?', passport.authenticate('digest', { + session: false + })) + router.all('/admin/(:path*)?', function (req, res, next) { + req.url = req.newUrl + next() + }) // pass in admin middleware! router.get('/admin', function (req, res) { @@ -81,9 +81,9 @@ function OKPush (options) { if (note.key in data.notifications) { data.notifications[ note.key ].last_push = note.last_push } - if (note.key in count) { - data.notifications[ note.key ].count = count[note.key] - } + }) + Object.keys(count).forEach(function(key){ + data.notifications[ key ].count = count[key] }) templates['index'].render(data).then(function(rendered) { res.send(rendered); @@ -91,6 +91,12 @@ function OKPush (options) { }) }) }) + + router.get('/list', function(req, res){ + db.getAllTokens("hub", function(err, hubz){ + res.json(hubz) + }) + }) router.post('/send', bodyParser.urlencoded({ extended: false }), function (req, res) { var key = req.body.key @@ -103,18 +109,21 @@ function OKPush (options) { }) // should work without middleware - router.post('/add', function (req, res) { + router.post('/add', bodyParser.urlencoded({ extended: false }), function (req, res) { db.addToken({ token: req.body.registrationId, channel: req.body.channel, platform: req.body.platform, }) + res.sendStatus(200) }) - router.post('/remove', function (req, res) { + + router.post('/remove', bodyParser.urlencoded({ extended: false }), function (req, res) { db.removeToken({ token: req.body.registrationId, channel: req.body.channel, }) + res.sendStatus(200) }) this._router = router diff --git a/lib/okpush/templates/index.liquid b/lib/okpush/templates/index.liquid index 1db77a58..36f688cc 100644 --- a/lib/okpush/templates/index.liquid +++ b/lib/okpush/templates/index.liquid @@ -39,7 +39,7 @@ tr:nth-child(2n+1) { Key Message Last Push - Registrations + Tokens {% for pair in notifications %} -- cgit v1.2.3-70-g09d2