mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 23:15:48 +01:00
closed #368 - notifications now no longer need scores
This commit is contained in:
@@ -15,28 +15,21 @@ 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);
|
||||
});
|
||||
});
|
||||
},
|
||||
@@ -51,7 +44,7 @@ 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);
|
||||
RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.datetime, nid);
|
||||
global.io.sockets.in('uid_' + uid).emit('event:new_notification');
|
||||
if (callback) callback(true);
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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('<strong>' + teaser.username + '</strong> has posted a reply to: "<strong>' + title + '</strong>"', null, nconf.get('relative_path') + '/topic/' + tid, 'topic:' + tid, function(nid) {
|
||||
notifications.create('<strong>' + teaser.username + '</strong> has posted a reply to: "<strong>' + title + '</strong>"', nconf.get('relative_path') + '/topic/' + tid, 'topic:' + tid, function(nid) {
|
||||
next(null, nid);
|
||||
});
|
||||
} else next(err);
|
||||
|
||||
22
src/user.js
22
src/user.js
@@ -578,7 +578,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
topics.getTopicField(tid, 'slug', function(err, slug) {
|
||||
var message = '<strong>' + username + '</strong> 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;
|
||||
|
||||
@@ -580,7 +580,7 @@ module.exports.init = function(io) {
|
||||
notifText = 'New message from <strong>' + username + '</strong>';
|
||||
|
||||
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) {
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user