Node.js based forum software built for the modern web
closes #1630
barisusaklie20920c5360c
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.jsindex bfe1489e2b..575e22c0f0 100644--- a/src/socket.io/posts.js+++ b/src/socket.io/posts.js@@ -105,6 +105,9 @@ function sendNotificationToPostOwner(data, uid, notification) {},slug: function(next) {topics.getTopicField(postData.tid, 'slug', next);+ },+ index: function(next) {+ posts.getPidIndex(data.pid, next);}}, function(err, results) {if (err) {@@ -113,7 +116,7 @@ function sendNotificationToPostOwner(data, uid, notification) {notifications.create({text: '[[' + notification + ', ' + results.username + ']]',- path: nconf.get('relative_path') + '/topic/' + results.slug + '#' + data.pid,+ path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,uniqueId: 'post:' + data.pid,from: uid}, function(nid) {@@ -277,7 +280,11 @@ SocketPosts.flag = function(socket, pid, callback) {topics.getTopicField(postData.tid, 'slug', next);},function(topicSlug, next) {- path = nconf.get('relative_path') + '/topic/' + topicSlug + '#' + pid;+ path = nconf.get('relative_path') + '/topic/' + topicSlug;+ posts.getPidIndex(pid, next);+ },+ function(postIndex, next) {+ path += '/' + postIndex;groups.get('administrators', {}, next);},function(adminGroup, next) {diff --git a/src/topics/follow.js b/src/topics/follow.jsindex 7e86d9a019..731963c623 100644--- a/src/topics/follow.js+++ b/src/topics/follow.js@@ -6,6 +6,7 @@ var async = require('async'),db = require('../database'),user = require('../user'),+ posts = require('../posts'),notifications = require('../notifications');module.exports = function(Topics) {@@ -22,24 +23,28 @@ module.exports = function(Topics) {Topics.notifyFollowers = function(tid, pid, exceptUid) {async.parallel({nid: function(next) {- Topics.getTopicFields(tid, ['title', 'slug'], function(err, topicData) {- if(err) {+ async.parallel({+ topicData: function(next) {+ Topics.getTopicFields(tid, ['title', 'slug'], next);+ },+ username: function(next) {+ user.getUserField(exceptUid, 'username', next);+ },+ postIndex: function(next) {+ posts.getPidIndex(pid, next);+ }+ }, function(err, results) {+ if (err) {return next(err);}- user.getUserField(exceptUid, 'username', function(err, username) {- if(err) {- return next(err);- }-- notifications.create({- text: '[[notifications:user_posted_to, ' + username + ', ' + topicData.title + ']]',- path: nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid,- uniqueId: 'topic:' + tid,- from: exceptUid- }, function(nid) {- next(null, nid);- });+ notifications.create({+ text: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',+ path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,+ uniqueId: 'topic:' + tid,+ from: exceptUid+ }, function(nid) {+ next(null, nid);});});},diff --git a/src/user/notifications.js b/src/user/notifications.jsindex 6dcc17da19..d2185c7a3a 100644--- a/src/user/notifications.js+++ b/src/user/notifications.js@@ -9,6 +9,7 @@ var async = require('async'),utils = require('../../public/src/utils'),db = require('../database'),notifications = require('../notifications'),+ posts = require('../posts'),topics = require('../topics');(function(UserNotifications) {@@ -146,22 +147,36 @@ var async = require('async'),};UserNotifications.sendPostNotificationToFollowers = function(uid, tid, pid) {- user.getUserField(uid, 'username', function(err, username) {- db.getSetMembers('followers:' + uid, function(err, followers) {- if (followers && followers.length) {- topics.getTopicField(tid, 'slug', function(err, slug) {- var message = '[[notifications:user_made_post, ' + username + ']]';-- notifications.create({- text: message,- path: nconf.get('relative_path') + '/topic/' + slug + '#' + pid,- uniqueId: 'topic:' + tid,- from: uid- }, function(nid) {- notifications.push(nid, followers);- });- });+ db.getSetMembers('followers:' + uid, function(err, followers) {+ if (err || !followers || !followers.length) {+ return;+ }++ async.parallel({+ usename: function(next) {+ user.getUserField(uid, 'username', next);+ },+ slug: function(next) {+ topics.getTopicField(tid, 'slug', next);+ },+ postIndex: function(next) {+ posts.getPidIndex(pid, next);+ }+ }, function(err, results) {+ if (err) {+ return;}++ var message = '[[notifications:user_made_post, ' + results.username + ']]';++ notifications.create({+ text: message,+ path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex,+ uniqueId: 'topic:' + tid,+ from: uid+ }, function(nid) {+ notifications.push(nid, followers);+ });});});};