diff --git a/src/user.js b/src/user.js index 568cbc4634..9d34bb75d4 100644 --- a/src/user.js +++ b/src/user.js @@ -749,7 +749,7 @@ var utils = require('./../public/src/utils.js'), get: function(uid, callback) { async.parallel({ unread: function(next) { - RDB.zrangebyscore('uid:' + uid + ':notifications:unread', 0, 10, function(err, nids) { + RDB.zrevrangebyscore('uid:' + uid + ':notifications:unread', 10, 0, function(err, nids) { var unread = []; if (nids && nids.length > 0) { async.eachSeries(nids, function(nid, next) { @@ -764,7 +764,7 @@ var utils = require('./../public/src/utils.js'), }); }, read: function(next) { - RDB.zrangebyscore('uid:' + uid + ':notifications:read', 0, 10, function(err, nids) { + RDB.zrevrangebyscore('uid:' + uid + ':notifications:read', 10, 0, function(err, nids) { var read = []; if (nids && nids.length > 0) { async.eachSeries(nids, function(nid, next) { @@ -779,6 +779,13 @@ var utils = require('./../public/src/utils.js'), }); } }, function(err, notifications) { + // While maintaining score sorting, sort by time + notifications.read.sort(function(a, b) { + if (a.score === b.score) return (a.datetime - b.datetime) > 0 ? -1 : 1; + }); + notifications.unread.sort(function(a, b) { + if (a.score === b.score) return (a.datetime - b.datetime) > 0 ? -1 : 1; + }); callback(notifications); }); }, diff --git a/src/webserver.js b/src/webserver.js index 72e5fa82d3..ac8ba2fccd 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -292,6 +292,9 @@ var express = require('express'), app.get('/api/:method/:id*', api_method); app.all('/test', function(req, res) { + notifications.create('normal 7', 5, '/topics/1', 'fteds', function(nid) { + notifications.push(nid, 1); + }); res.send(); }); @@ -300,7 +303,9 @@ var express = require('express'), app.get('/graph/users/:username/picture', function(req, res) { user.get_uid_by_username(req.params.username, function(uid) { if (uid == null) { - res.send('{status:0}'); + res.json({ + status: 0 + }); return; } user.getUserField(uid, 'picture', function(picture) {