notification fixes

made post notifications unique per post so they dont overwrite other
types.
v1.18.x
barisusakli 11 years ago
parent 9466d7ced4
commit b3d9db10f2

@ -170,7 +170,32 @@ module.exports = function(db, module) {
};
module.sortedSetsCard = function(keys, callback) {
async.map(keys, module.sortedSetCard, callback);
var pipeline = [
{ $match : { _key : { $in: keys } } } ,
{ $group: { _id: {_key: '$_key'}, count: { $sum: 1 } } },
{ $project: { _id: 1, count: '$count' } }
];
db.collection('objects').aggregate(pipeline, function(err, results) {
if (err) {
return callback(err);
}
if (!Array.isArray(results)) {
results = [];
}
var map = {};
results.forEach(function(item) {
if (item && item._id._key) {
map[item._id._key] = item.count;
}
});
results = keys.map(function(key) {
return map[key] || 0;
});
callback(null, results);
});
};
module.sortedSetRank = function(key, value, callback) {

@ -95,7 +95,7 @@ var async = require('async'),
if (oldNotification) {
if (parseInt(oldNotification.pid, 10) === parseInt(data.pid, 10) && parseInt(oldNotification.importance, 10) > parseInt(data.importance, 10)) {
return callback(null, null);
return callback();
}
}

@ -353,7 +353,7 @@ SocketTopics.sendNotificationToTopicOwner = function(tid, fromuid, notification)
notifications.create({
bodyShort: '[[' + notification + ', ' + results.username + ']]',
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug,
nid: 'topic:' + tid + ':uid:' + fromuid,
nid: 'tid:' + tid + ':uid:' + fromuid,
from: fromuid
}, function(err, notification) {
if (!err && notification) {

@ -198,7 +198,7 @@ SocketUser.follow = function(socket, data, callback) {
notifications.create({
bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]',
path: nconf.get('relative_path') + '/user/' + userData.userslug,
nid: 'follow:uid:' + socket.uid,
nid: 'follow:' + data.uid + ':uid:' + socket.uid,
from: socket.uid
}, function(err, notification) {
if (!err && notification) {

@ -56,7 +56,7 @@ module.exports = function(Topics) {
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.title + ']]',
bodyLong: results.postContent,
pid: pid,
nid: 'topic:' + tid + ':uid:' + exceptUid,
nid: 'tid:' + tid + ':pid:' + pid + ':uid:' + exceptUid,
tid: tid,
from: exceptUid
}, function(err, notification) {

@ -284,7 +284,7 @@ var async = require('async'),
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]',
bodyLong: results.postContent,
pid: pid,
nid: 'topic:' + tid + ':uid:' + uid,
nid: 'tid:' + tid + ':pid:' + pid + ':uid:' + uid,
tid: tid,
from: uid
}, function(err, notification) {

Loading…
Cancel
Save