From cf85cc2b75b9c3ead3a693b6fa0feeca5b9e70ba Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 19 Feb 2017 01:23:53 +0100 Subject: counts --- lib/okpush/db.js | 17 +++++++++++++++-- lib/okpush/index.js | 35 +++++++++++++++++++---------------- lib/okpush/templates/index.liquid | 6 ++++-- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/lib/okpush/db.js b/lib/okpush/db.js index ad18b7b3..f64acf69 100644 --- a/lib/okpush/db.js +++ b/lib/okpush/db.js @@ -77,8 +77,21 @@ function getAllTokens (channel, cb) { function removeToken (data) { PushToken.find(data).remove().exec() } -function getDeviceCount (channel, cb) { - PushToken.count({ channel: channel }, cb) +function getDeviceCount (channels, cb) { + var countz = {} + get_next() + function get_next() { + var channel = channels.pop() + PushToken.count({ channel: channel }, function(err, count){ + countz[channel] = count + if (channels.length) { + return get_next() + } + else { + cb(countz) + } + }) + } } /* notifications */ diff --git a/lib/okpush/index.js b/lib/okpush/index.js index 2fe59932..df9c8265 100644 --- a/lib/okpush/index.js +++ b/lib/okpush/index.js @@ -50,37 +50,40 @@ 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) { - 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) { - // change this to get notification counts for each channel db.getNotifications(function(err, notes){ - db.getDeviceCount(function(err, count){ + var channels = Object.keys(config.notifications) + db.getDeviceCount(channels, function(count){ var data = { meta: meta, notifications: config.notifications, - device_count: count, } notes.forEach(function(note){ 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] + } }) templates['index'].render(data).then(function(rendered) { res.send(rendered); diff --git a/lib/okpush/templates/index.liquid b/lib/okpush/templates/index.liquid index 10772b55..1db77a58 100644 --- a/lib/okpush/templates/index.liquid +++ b/lib/okpush/templates/index.liquid @@ -34,13 +34,12 @@ tr:nth-child(2n+1) {

Push Notifications

-
Device count: {{ device_count }}
- + {% for pair in notifications %} @@ -60,6 +59,9 @@ tr:nth-child(2n+1) { {{ spec.last_push | date: "%a %d-%b-%Y %H:%M" }} {% endunless %} + -- cgit v1.2.3-70-g09d2
Key Message Last PushRegistrations
+ {{spec.count}} +