notifications page + ajaxify route + css styling

This commit is contained in:
Julian Lam
2013-10-22 14:35:20 -04:00
parent 5c70b2b307
commit 705571de8c
6 changed files with 74 additions and 1 deletions

View File

@@ -945,6 +945,36 @@ var utils = require('./../public/src/utils.js'),
callback(notifications);
});
},
getAll: function(uid, limit, before, callback) {
var now = new Date();
if (!limit || parseInt(limit) <= 0) limit = 25;
if (before) before = new Date(parseInt(before, 10));
RDB.multi()
.zrevrangebyscore('uid:' + uid + ':notifications:read', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
.zrevrangebyscore('uid:' + uid + ':notifications:unread', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
.exec(function(err, results) {
// Merge the read and unread notifications
var nids = results[0].concat(results[1]);
async.map(nids, function(nid, next) {
notifications.get(nid, function(notif_data) {
next(null, notif_data);
});
}, function(err, notifs) {
notifs = notifs.sort(function(a, b) {
return parseInt(b.datetime, 10) - parseInt(a.datetime, 10);
}).map(function(notif) {
notif.datetimeISO = new Date(parseInt(notif.datetime, 10)).toISOString();
return notif;
});
callback(err, notifs);
})
});
},
getUnreadCount: function(uid, callback) {
RDB.zcount('uid:' + uid + ':notifications:unread', 0, 10, callback);
},