Skip to content

Commit

Permalink
fixed #30
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Jun 24, 2013
1 parent a6ff96c commit 578dba1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
});
},
Expand Down
7 changes: 6 additions & 1 deletion src/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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) {
Expand Down

0 comments on commit 578dba1

Please sign in to comment.