mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
uniqueId support in notifications
This commit is contained in:
@@ -5,13 +5,14 @@ var config = require('../config.js'),
|
||||
|
||||
(function(Notifications) {
|
||||
Notifications.get = function(nid, callback) {
|
||||
RDB.hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', function(err, notification) {
|
||||
RDB.hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', 'uniqueId', function(err, notification) {
|
||||
callback({
|
||||
nid: nid,
|
||||
text: notification[0],
|
||||
score: notification[1],
|
||||
path: notification[2],
|
||||
datetime: notification[3]
|
||||
datetime: notification[3],
|
||||
uniqueId: notification[4]
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -51,13 +52,52 @@ var config = require('../config.js'),
|
||||
Notifications.get(nid, function(notif_data) {
|
||||
for(x=0;x<numUids;x++) {
|
||||
if (parseInt(uids[x]) > 0) {
|
||||
RDB.zadd('uid:' + uids[x] + ':notifications:unread', notif_data.score, nid);
|
||||
(function(uid) {
|
||||
Notifications.remove_by_uniqueId(notif_data.uniqueId, uid, function() {
|
||||
RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.score, nid);
|
||||
if (callback) callback(true);
|
||||
});
|
||||
})(uids[x]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Notifications.remove_by_uniqueId = function(uniqueId, uid, callback) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
|
||||
if (nids && nids.length > 0) {
|
||||
async.each(nids, function(nid, next) {
|
||||
Notifications.get(nid, function(nid_info) {
|
||||
if (nid_info.uniqueId === uniqueId) RDB.zrem('uid:' + uid + ':notifications:unread', nid);
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
next();
|
||||
});
|
||||
} else next();
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
RDB.zrange('uid:' + uid + ':notifications:read', 0, -1, function(err, nids) {
|
||||
if (nids && nids.length > 0) {
|
||||
async.each(nids, function(nid, next) {
|
||||
Notifications.get(nid, function(nid_info) {
|
||||
if (nid_info.uniqueId === uniqueId) RDB.zrem('uid:' + uid + ':notifications:read', nid);
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
next();
|
||||
});
|
||||
} else next();
|
||||
});
|
||||
}
|
||||
], function(err) {
|
||||
if (!err) callback(true);
|
||||
});
|
||||
}
|
||||
|
||||
Notifications.mark_read = function(nid, uid, callback) {
|
||||
if (parseInt(uid) > 0) {
|
||||
Notifications.get(nid, function(notif_data) {
|
||||
|
||||
@@ -240,14 +240,14 @@ var express = require('express'),
|
||||
app.get('/api/:method/:id*', api_method);
|
||||
|
||||
app.get('/test', function(req, res) {
|
||||
notifications.mark_read_multiple([1, 2], 1, function(success) {
|
||||
res.send('mark: ' + success);
|
||||
// notifications.remove_by_uniqueId('foobar', 1, function(success) {
|
||||
// res.send('remove: ' + success);
|
||||
// });
|
||||
notifications.create('a bunch more text', 5, '/category/2/general-discussion', 'foobar', function(nid) {
|
||||
notifications.push(nid, 1, function() {
|
||||
res.send('nid: ' + nid)
|
||||
});
|
||||
});
|
||||
// notifications.create('some text', 5, '/category/2/general-discussion', function(nid) {
|
||||
// notifications.push(nid, 1, function() {
|
||||
// res.send('nid: ', nid)
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user