mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-04 13:37:38 +02:00
refactored notifications library to mark all notifs read when the menu is
opened (closes #134)
This commit is contained in:
@@ -100,7 +100,7 @@ var RDB = require('./redis.js'),
|
||||
notifications.get(nid, function(notif_data) {
|
||||
RDB.zrem('uid:' + uid + ':notifications:unread', nid);
|
||||
RDB.zadd('uid:' + uid + ':notifications:read', notif_data.score, nid);
|
||||
if (callback) callback(true);
|
||||
if (callback) callback();
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -108,11 +108,22 @@ var RDB = require('./redis.js'),
|
||||
if (!Array.isArray(nids) && parseInt(nids, 10) > 0) nids = [nids];
|
||||
|
||||
async.each(nids, function(nid, next) {
|
||||
notifications.mark_read(nid, uid, function(success) {
|
||||
if (success) next(null);
|
||||
notifications.mark_read(nid, uid, function(err) {
|
||||
if (!err) next(null);
|
||||
});
|
||||
}, function(err) {
|
||||
if (callback && !err) callback(true);
|
||||
if (callback) callback(err);
|
||||
});
|
||||
},
|
||||
mark_all_read: function(uid, callback) {
|
||||
RDB.zrange('uid:' + uid + ':notifications:unread', 0, 10, function(err, nids) {
|
||||
if (err) return callback(err);
|
||||
|
||||
if (nids.length > 0) {
|
||||
notifications.mark_read_multiple(nids, uid, function(err) {
|
||||
callback(err);
|
||||
});
|
||||
} else callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -121,5 +132,6 @@ module.exports = {
|
||||
get: notifications.get,
|
||||
create: notifications.create,
|
||||
push: notifications.push,
|
||||
mark_read: notifications.mark_read_multiple
|
||||
mark_read: notifications.mark_read_multiple,
|
||||
mark_all_read: notifications.mark_all_read
|
||||
}
|
||||
16
src/user.js
16
src/user.js
@@ -1057,22 +1057,6 @@ var utils = require('./../public/src/utils.js'),
|
||||
},
|
||||
getUnreadCount: function(uid, callback) {
|
||||
RDB.zcount('uid:' + uid + ':notifications:unread', 0, 10, callback);
|
||||
},
|
||||
hasFlag: function(uid, callback) {
|
||||
RDB.get('uid:1:notifications:flag', function(err, flag) {
|
||||
if (err) {
|
||||
RDB.handle(err);
|
||||
}
|
||||
|
||||
callback(flag === 1);
|
||||
});
|
||||
},
|
||||
removeFlag: function(uid) {
|
||||
RDB.del('uid:' + uid + ':notifications:flag', function(err) {
|
||||
if (err) {
|
||||
RDB.handle(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}(exports));
|
||||
|
||||
@@ -409,20 +409,16 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:notifications.hasFlag', function(data) {
|
||||
user.notifications.hasFlag(uid, function(flag) {
|
||||
socket.emit('api:notifications.hasFlag', flag);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:notifications.removeFlag', function() {
|
||||
user.notifications.removeFlag(uid);
|
||||
});
|
||||
|
||||
socket.on('api:notifications.mark_read', function(nid) {
|
||||
notifications.mark_read(nid, uid);
|
||||
});
|
||||
|
||||
socket.on('api:notifications.mark_all_read', function(data, callback) {
|
||||
notifications.mark_all_read(uid, function(err) {
|
||||
if (!err) callback();
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:categories.getRecentReplies', function(tid) {
|
||||
categories.getRecentReplies(tid, 4, function(replies) {
|
||||
socket.emit('api:categories.getRecentReplies', replies);
|
||||
|
||||
Reference in New Issue
Block a user