Skip to content

Node.js based forum software built for the modern web

notification fixes

barisusaklib3d9db10f2d9
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js
index a1dd33576f..78a8d629fe 100644
--- a/src/database/mongo/sorted.js
+++ b/src/database/mongo/sorted.js
@@ -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) {
diff --git a/src/notifications.js b/src/notifications.js
index 328e033502..b1ac1639f6 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -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();
}
}
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index 666b62d244..500fae9cc6 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -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) {
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index 43bb934bdb..44d6f4b41c 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -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) {
diff --git a/src/topics/follow.js b/src/topics/follow.js
index 9c711ad440..588d629c82 100644
--- a/src/topics/follow.js
+++ b/src/topics/follow.js
@@ -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) {
diff --git a/src/user/notifications.js b/src/user/notifications.js
index caa9fe5ef4..08703d6237 100644
--- a/src/user/notifications.js
+++ b/src/user/notifications.js
@@ -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) {