|
|
@ -3,15 +3,22 @@ var RDB = require('./redis.js'),
|
|
|
|
utils = require('../public/src/utils.js'),
|
|
|
|
utils = require('../public/src/utils.js'),
|
|
|
|
|
|
|
|
|
|
|
|
notifications = {
|
|
|
|
notifications = {
|
|
|
|
get: function(nid, callback) {
|
|
|
|
get: function(nid, uid, callback) {
|
|
|
|
RDB.hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', 'uniqueId', function(err, notification) {
|
|
|
|
RDB.multi()
|
|
|
|
|
|
|
|
.hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', 'uniqueId')
|
|
|
|
|
|
|
|
.zrank('uid:' + uid + ':notifications:read', nid)
|
|
|
|
|
|
|
|
.exec(function(err, results) {
|
|
|
|
|
|
|
|
var notification = results[0]
|
|
|
|
|
|
|
|
readIdx = results[1];
|
|
|
|
|
|
|
|
|
|
|
|
callback({
|
|
|
|
callback({
|
|
|
|
nid: nid,
|
|
|
|
nid: nid,
|
|
|
|
text: notification[0],
|
|
|
|
text: notification[0],
|
|
|
|
score: notification[1],
|
|
|
|
score: notification[1],
|
|
|
|
path: notification[2],
|
|
|
|
path: notification[2],
|
|
|
|
datetime: notification[3],
|
|
|
|
datetime: notification[3],
|
|
|
|
uniqueId: notification[4]
|
|
|
|
uniqueId: notification[4],
|
|
|
|
|
|
|
|
read: readIdx !== null ? true : false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -39,7 +46,7 @@ var RDB = require('./redis.js'),
|
|
|
|
var numUids = uids.length,
|
|
|
|
var numUids = uids.length,
|
|
|
|
x;
|
|
|
|
x;
|
|
|
|
|
|
|
|
|
|
|
|
notifications.get(nid, function(notif_data) {
|
|
|
|
notifications.get(nid, null, function(notif_data) {
|
|
|
|
for (x = 0; x < numUids; x++) {
|
|
|
|
for (x = 0; x < numUids; x++) {
|
|
|
|
if (parseInt(uids[x]) > 0) {
|
|
|
|
if (parseInt(uids[x]) > 0) {
|
|
|
|
(function(uid) {
|
|
|
|
(function(uid) {
|
|
|
@ -59,7 +66,7 @@ var RDB = require('./redis.js'),
|
|
|
|
RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
|
|
|
|
RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
|
|
|
|
if (nids && nids.length > 0) {
|
|
|
|
if (nids && nids.length > 0) {
|
|
|
|
async.each(nids, function(nid, next) {
|
|
|
|
async.each(nids, function(nid, next) {
|
|
|
|
notifications.get(nid, function(nid_info) {
|
|
|
|
notifications.get(nid, uid, function(nid_info) {
|
|
|
|
if (nid_info.uniqueId === uniqueId) RDB.zrem('uid:' + uid + ':notifications:unread', nid);
|
|
|
|
if (nid_info.uniqueId === uniqueId) RDB.zrem('uid:' + uid + ':notifications:unread', nid);
|
|
|
|
next();
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -73,7 +80,7 @@ var RDB = require('./redis.js'),
|
|
|
|
RDB.zrange('uid:' + uid + ':notifications:read', 0, -1, function(err, nids) {
|
|
|
|
RDB.zrange('uid:' + uid + ':notifications:read', 0, -1, function(err, nids) {
|
|
|
|
if (nids && nids.length > 0) {
|
|
|
|
if (nids && nids.length > 0) {
|
|
|
|
async.each(nids, function(nid, next) {
|
|
|
|
async.each(nids, function(nid, next) {
|
|
|
|
notifications.get(nid, function(nid_info) {
|
|
|
|
notifications.get(nid, uid, function(nid_info) {
|
|
|
|
if (nid_info.uniqueId === uniqueId) RDB.zrem('uid:' + uid + ':notifications:read', nid);
|
|
|
|
if (nid_info.uniqueId === uniqueId) RDB.zrem('uid:' + uid + ':notifications:read', nid);
|
|
|
|
next();
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -89,7 +96,7 @@ var RDB = require('./redis.js'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mark_read: function(nid, uid, callback) {
|
|
|
|
mark_read: function(nid, uid, callback) {
|
|
|
|
if (parseInt(uid) > 0) {
|
|
|
|
if (parseInt(uid) > 0) {
|
|
|
|
notifications.get(nid, function(notif_data) {
|
|
|
|
notifications.get(nid, uid, function(notif_data) {
|
|
|
|
RDB.zrem('uid:' + uid + ':notifications:unread', nid);
|
|
|
|
RDB.zrem('uid:' + uid + ':notifications:unread', nid);
|
|
|
|
RDB.zadd('uid:' + uid + ':notifications:read', notif_data.datetime, nid);
|
|
|
|
RDB.zadd('uid:' + uid + ':notifications:read', notif_data.datetime, nid);
|
|
|
|
if (callback) callback();
|
|
|
|
if (callback) callback();
|
|
|
|