v1.18.x
barisusakli 11 years ago
parent 0574022e02
commit e20920c536

@ -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) {

@ -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);
});
});
},

@ -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);
});
});
});
};

Loading…
Cancel
Save