diff --git a/src/notifications.js b/src/notifications.js index c2fb26cd26..d2e1477aac 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -15,29 +15,22 @@ var RDB = require('./redis.js'), }); }); }, - create: function(text, score, path, uniqueId, callback) { - /* - * Score guide: - * 0 Low priority messages (probably unused) - * 5 Normal messages - * 10 High priority messages - * + create: function(text, path, uniqueId, callback) { + /** * uniqueId is used solely to override stale nids. * If a new nid is pushed to a user and an existing nid in the user's * (un)read list contains the same uniqueId, it will be removed, and * the new one put in its place. */ RDB.incr('notifications:next_nid', function(err, nid) { - RDB.hmset( - 'notifications:' + nid, - 'text', text || '', - 'score', score || 5, - 'path', path || null, - 'datetime', Date.now(), - 'uniqueId', uniqueId || utils.generateUUID(), - function(err, status) { - if (status === 'OK') callback(nid); - }); + RDB.hmset('notifications:' + nid, { + text: text || '', + path: path || null, + datetime: Date.now(), + uniqueId: uniqueId || utils.generateUUID() + }, function(err, status) { + if (!err) callback(nid); + }); }); }, push: function(nid, uids, callback) { @@ -51,8 +44,8 @@ var RDB = require('./redis.js'), if (parseInt(uids[x]) > 0) { (function(uid) { notifications.remove_by_uniqueId(notif_data.uniqueId, uid, function() { - RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.score, nid); - global.io.sockets. in ('uid_' + uid).emit('event:new_notification'); + RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.datetime, nid); + global.io.sockets.in('uid_' + uid).emit('event:new_notification'); if (callback) callback(true); }); })(uids[x]); @@ -98,7 +91,7 @@ var RDB = require('./redis.js'), if (parseInt(uid) > 0) { notifications.get(nid, function(notif_data) { RDB.zrem('uid:' + uid + ':notifications:unread', nid); - RDB.zadd('uid:' + uid + ':notifications:read', notif_data.score, nid); + RDB.zadd('uid:' + uid + ':notifications:read', notif_data.datetime, nid); if (callback) callback(); }); } diff --git a/src/threadTools.js b/src/threadTools.js index 23b641f0d2..bd0c1a126c 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -276,7 +276,7 @@ var RDB = require('./redis.js'), topics.getTopicField(tid, 'title', function(err, title) { topics.getTeaser(tid, function(err, teaser) { if (!err) { - notifications.create('' + teaser.username + ' has posted a reply to: "' + title + '"', null, nconf.get('relative_path') + '/topic/' + tid, 'topic:' + tid, function(nid) { + notifications.create('' + teaser.username + ' has posted a reply to: "' + title + '"', nconf.get('relative_path') + '/topic/' + tid, 'topic:' + tid, function(nid) { next(null, nid); }); } else next(err); diff --git a/src/user.js b/src/user.js index bbe6779303..4c6ccfc811 100644 --- a/src/user.js +++ b/src/user.js @@ -578,7 +578,7 @@ var utils = require('./../public/src/utils.js'), topics.getTopicField(tid, 'slug', function(err, slug) { var message = '' + username + ' made a new post'; - notifications.create(message, 5, nconf.get('relative_path') + '/topic/' + slug + '#' + pid, 'topic:' + tid, function(nid) { + notifications.create(message, nconf.get('relative_path') + '/topic/' + slug + '#' + pid, 'topic:' + tid, function(nid) { notifications.push(nid, followers); }); }); @@ -888,7 +888,7 @@ var utils = require('./../public/src/utils.js'), async.parallel({ unread: function(next) { - RDB.zrevrangebyscore('uid:' + uid + ':notifications:unread', 10, 0, function(err, nids) { + RDB.zrevrange('uid:' + uid + ':notifications:unread', 0, 10, function(err, nids) { // @todo handle err var unread = []; @@ -910,7 +910,7 @@ var utils = require('./../public/src/utils.js'), }); }, read: function(next) { - RDB.zrevrangebyscore('uid:' + uid + ':notifications:read', 10, 0, function(err, nids) { + RDB.zrevrange('uid:' + uid + ':notifications:read', 0, 10, function(err, nids) { // @todo handle err var read = []; @@ -932,22 +932,6 @@ var utils = require('./../public/src/utils.js'), }); } }, function(err, notifications) { - // While maintaining score sorting, sort by time - var readCount = notifications.read.length, - unreadCount = notifications.unread.length; - - 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; - } - }); - // Limit the number of notifications to `maxNotifs`, prioritising unread notifications if (notifications.read.length + notifications.unread.length > maxNotifs) { notifications.read.length = maxNotifs - notifications.unread.length; diff --git a/src/websockets.js b/src/websockets.js index 27cdb0ef8a..90784ad847 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -580,7 +580,7 @@ module.exports.init = function(io) { notifText = 'New message from ' + username + ''; if (!isUserOnline(touid)) { - notifications.create(notifText, 5, 'javascript:app.openChat('' + username + '', ' + uid + ');', 'notification_' + uid + '_' + touid, function(nid) { + notifications.create(notifText, 'javascript:app.openChat('' + username + '', ' + uid + ');', 'notification_' + uid + '_' + touid, function(nid) { notifications.push(nid, [touid], function(success) { });