style changes

v1.18.x
barisusakli 9 years ago
parent 1501eda311
commit b446ff42c3

@ -3,7 +3,6 @@
var async = require('async'); var async = require('async');
var winston = require('winston'); var winston = require('winston');
var S = require('string'); var S = require('string');
var nconf = require('nconf');
var websockets = require('./index'); var websockets = require('./index');
var user = require('../user'); var user = require('../user');
@ -53,24 +52,24 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification)
if (!pid || !fromuid || !notification) { if (!pid || !fromuid || !notification) {
return; return;
} }
posts.getPostFields(pid, ['tid', 'uid', 'content'], function(err, postData) { fromuid = parseInt(fromuid, 10);
if (err) { var postData;
return; async.waterfall([
} function (next) {
posts.getPostFields(pid, ['tid', 'uid', 'content'], next);
if (!postData.uid || fromuid === parseInt(postData.uid, 10)) { },
return; function (_postData, next) {
} postData = _postData;
if (!postData.uid || fromuid === parseInt(postData.uid, 10)) {
async.parallel({
username: async.apply(user.getUserField, fromuid, 'username'),
topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'),
postObj: async.apply(posts.parsePost, postData)
}, function(err, results) {
if (err) {
return; return;
} }
async.parallel({
username: async.apply(user.getUserField, fromuid, 'username'),
topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'),
postObj: async.apply(posts.parsePost, postData)
}, next);
},
function (results, next) {
var title = S(results.topicTitle).decodeHTMLEntities().s; var title = S(results.topicTitle).decodeHTMLEntities().s;
var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ','); var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
@ -83,12 +82,15 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification)
from: fromuid, from: fromuid,
mergeId: notification + '|' + pid, mergeId: notification + '|' + pid,
topicTitle: results.topicTitle topicTitle: results.topicTitle
}, function(err, notification) { }, next);
if (!err && notification) { }
notifications.push(notification, [postData.uid]); ], function(err, notification) {
} if (err) {
}); return winston.error(err);
}); }
if (notification) {
notifications.push(notification, [postData.uid]);
}
}); });
}; };
@ -98,27 +100,38 @@ SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, notification
return; return;
} }
async.parallel({ fromuid = parseInt(fromuid, 10);
username: async.apply(user.getUserField, fromuid, 'username'),
topicData: async.apply(topics.getTopicFields, tid, ['uid', 'slug', 'title']),
}, function(err, results) {
if (err || fromuid === parseInt(results.topicData.uid, 10)) {
return;
}
var title = S(results.topicData.title).decodeHTMLEntities().s; var ownerUid;
var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ','); async.waterfall([
function (next) {
notifications.create({ async.parallel({
bodyShort: '[[' + notification + ', ' + results.username + ', ' + titleEscaped + ']]', username: async.apply(user.getUserField, fromuid, 'username'),
path: '/topic/' + results.topicData.slug, topicData: async.apply(topics.getTopicFields, tid, ['uid', 'slug', 'title']),
nid: 'tid:' + tid + ':uid:' + fromuid, }, next);
from: fromuid },
}, function(err, notification) { function (results, next) {
if (!err && notification) { if (fromuid === parseInt(results.topicData.uid, 10)) {
notifications.push(notification, [results.topicData.uid]); return;
} }
}); ownerUid = results.topicData.uid;
var title = S(results.topicData.title).decodeHTMLEntities().s;
var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
notifications.create({
bodyShort: '[[' + notification + ', ' + results.username + ', ' + titleEscaped + ']]',
path: '/topic/' + results.topicData.slug,
nid: 'tid:' + tid + ':uid:' + fromuid,
from: fromuid
}, next);
}
], function(err, notification) {
if (err) {
return winston.error(err);
}
if (notification && parseInt(ownerUid, 10)) {
notifications.push(notification, [ownerUid]);
}
}); });
}; };

@ -200,13 +200,20 @@ var privileges = require('../privileges');
}; };
UserNotifications.sendTopicNotificationToFollowers = function(uid, topicData, postData) { UserNotifications.sendTopicNotificationToFollowers = function(uid, topicData, postData) {
db.getSortedSetRange('followers:' + uid, 0, -1, function(err, followers) { var followers;
if (err || !Array.isArray(followers) || !followers.length) { async.waterfall([
return; function (next) {
} db.getSortedSetRange('followers:' + uid, 0, -1, next);
},
privileges.categories.filterUids('read', topicData.cid, followers, function(err, followers) { function (followers, next) {
if (err || !followers.length) { if (!Array.isArray(followers) || !followers.length) {
return;
}
privileges.categories.filterUids('read', topicData.cid, followers, next);
},
function (_followers, next) {
followers = _followers;
if (!followers.length) {
return; return;
} }
@ -223,12 +230,16 @@ var privileges = require('../privileges');
nid: 'tid:' + postData.tid + ':uid:' + uid, nid: 'tid:' + postData.tid + ':uid:' + uid,
tid: postData.tid, tid: postData.tid,
from: uid from: uid
}, function(err, notification) { }, next);
if (!err && notification) { }
notifications.push(notification, followers); ], function(err, notification) {
} if (err) {
}); return winston.error(err);
}); }
if (notification) {
notifications.push(notification, followers);
}
}); });
}; };

Loading…
Cancel
Save