final pass, #999

This commit is contained in:
Julian Lam
2014-02-14 11:04:00 -05:00
parent 8bd6f85478
commit d0d3160fc7
2 changed files with 38 additions and 13 deletions

View File

@@ -19,18 +19,37 @@ var async = require('async'),
Notifications.get = function(nid, uid, callback) {
db.exists('notifications:' + nid, function(err, exists) {
if(!exists) {
if (err) {
winston.error('[notifications.get] Could not retrieve nid ' + nid + ': ' + err.message);
return callback(null);
}
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
if (exists) {
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
db.getObjectFields('notifications:' + nid, ['nid', 'text', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {
db.getObjectFields('notifications:' + nid, ['nid', 'text', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {
notification.read = rank !== null ? true:false;
callback(notification);
notification.read = rank !== null ? true:false;
callback(notification);
});
});
});
} else {
// Remove from the user's boxes
if (process.env.NODE_ENV === 'development') {
winston.info('[notifications.get] nid ' + nid + ' not found. Removing.');
}
async.parallel([
function(next) {
db.sortedSetRemove('uid:' + uid + ':notifications:unread', nid, next);
},
function(next) {
db.sortedSetRemove('uid:' + uid + ':notifications:read', nid, next);
}
], function(err) {
callback(null);
});
}
});
};