v1.18.x
barisusakli
parent 0574022e02
commit e20920c536

@ -105,6 +105,9 @@ function sendNotificationToPostOwner(data, uid, notification) {
}, },
slug: function(next) { slug: function(next) {
topics.getTopicField(postData.tid, 'slug', next); topics.getTopicField(postData.tid, 'slug', next);
},
index: function(next) {
posts.getPidIndex(data.pid, next);
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {
@ -113,7 +116,7 @@ function sendNotificationToPostOwner(data, uid, notification) {
notifications.create({ notifications.create({
text: '[[' + notification + ', ' + results.username + ']]', 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, uniqueId: 'post:' + data.pid,
from: uid from: uid
}, function(nid) { }, function(nid) {
@ -277,7 +280,11 @@ SocketPosts.flag = function(socket, pid, callback) {
topics.getTopicField(postData.tid, 'slug', next); topics.getTopicField(postData.tid, 'slug', next);
}, },
function(topicSlug, 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); groups.get('administrators', {}, next);
}, },
function(adminGroup, next) { function(adminGroup, next) {

@ -6,6 +6,7 @@ var async = require('async'),
db = require('../database'), db = require('../database'),
user = require('../user'), user = require('../user'),
posts = require('../posts'),
notifications = require('../notifications'); notifications = require('../notifications');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -22,26 +23,30 @@ module.exports = function(Topics) {
Topics.notifyFollowers = function(tid, pid, exceptUid) { Topics.notifyFollowers = function(tid, pid, exceptUid) {
async.parallel({ async.parallel({
nid: function(next) { nid: function(next) {
Topics.getTopicFields(tid, ['title', 'slug'], function(err, topicData) { async.parallel({
if(err) { topicData: function(next) {
return next(err); Topics.getTopicFields(tid, ['title', 'slug'], next);
},
username: function(next) {
user.getUserField(exceptUid, 'username', next);
},
postIndex: function(next) {
posts.getPidIndex(pid, next);
} }
}, function(err, results) {
user.getUserField(exceptUid, 'username', function(err, username) { if (err) {
if(err) {
return next(err); return next(err);
} }
notifications.create({ notifications.create({
text: '[[notifications:user_posted_to, ' + username + ', ' + topicData.title + ']]', text: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',
path: nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid, path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,
uniqueId: 'topic:' + tid, uniqueId: 'topic:' + tid,
from: exceptUid from: exceptUid
}, function(nid) { }, function(nid) {
next(null, nid); next(null, nid);
}); });
}); });
});
}, },
followers: function(next) { followers: function(next) {
Topics.getFollowers(tid, next); Topics.getFollowers(tid, next);

@ -9,6 +9,7 @@ var async = require('async'),
utils = require('../../public/src/utils'), utils = require('../../public/src/utils'),
db = require('../database'), db = require('../database'),
notifications = require('../notifications'), notifications = require('../notifications'),
posts = require('../posts'),
topics = require('../topics'); topics = require('../topics');
(function(UserNotifications) { (function(UserNotifications) {
@ -146,23 +147,37 @@ var async = require('async'),
}; };
UserNotifications.sendPostNotificationToFollowers = function(uid, tid, pid) { UserNotifications.sendPostNotificationToFollowers = function(uid, tid, pid) {
user.getUserField(uid, 'username', function(err, username) {
db.getSetMembers('followers:' + uid, function(err, followers) { db.getSetMembers('followers:' + uid, function(err, followers) {
if (followers && followers.length) { if (err || !followers || !followers.length) {
topics.getTopicField(tid, 'slug', function(err, slug) { return;
var message = '[[notifications:user_made_post, ' + username + ']]'; }
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({ notifications.create({
text: message, text: message,
path: nconf.get('relative_path') + '/topic/' + slug + '#' + pid, path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex,
uniqueId: 'topic:' + tid, uniqueId: 'topic:' + tid,
from: uid from: uid
}, function(nid) { }, function(nid) {
notifications.push(nid, followers); notifications.push(nid, followers);
}); });
}); });
}
});
}); });
}; };

Loading…
Cancel
Save