minor tweaks

v1.18.x
barisusakli 10 years ago
parent 1ddb90720c
commit 7b49effc14

@ -43,12 +43,15 @@ var winston = require('winston'),
async.parallel({ async.parallel({
post: function(next) { post: function(next) {
posts.setPostFields(data.pid, { var d = {
edited: Date.now(), edited: Date.now(),
editor: data.uid, editor: data.uid,
handle: data.handle,
content: postData.content content: postData.content
}, next); };
if (data.handle) {
d.handle = data.handle;
}
posts.setPostFields(data.pid, d, next);
}, },
topic: function(next) { topic: function(next) {
var tid = postData.tid; var tid = postData.tid;

@ -14,7 +14,6 @@ module.exports = function(Posts) {
Posts.create = function(data, callback) { Posts.create = function(data, callback) {
var uid = data.uid, var uid = data.uid,
tid = data.tid, tid = data.tid,
handle = data.uid ? null : data.handle, // Only guests have handles!
content = data.content, content = data.content,
timestamp = data.timestamp || Date.now(); timestamp = data.timestamp || Date.now();
@ -51,8 +50,8 @@ module.exports = function(Posts) {
postData.ip = data.ip; postData.ip = data.ip;
} }
if (handle) { if (parseInt(uid, 10) === 0 && data.handle) {
postData.handle = handle; postData.handle = data.handle;
} }
plugins.fireHook('filter:post.save', postData, next); plugins.fireHook('filter:post.save', postData, next);

@ -155,7 +155,7 @@ module.exports = function(Topics) {
}); });
}, },
topicData: function(next) { topicData: function(next) {
Topics.getTopicsByTids([postData.tid], 0, next); Topics.getTopicsByTids([postData.tid], uid, next);
} }
}, next); }, next);
}, },

@ -108,15 +108,15 @@ module.exports = function(Topics) {
posts.getPostIndices(postData, uid, next); posts.getPostIndices(postData, uid, next);
} }
}, function(err, results) { }, function(err, results) {
if(err) { if (err) {
return callback(err); return callback(err);
} }
postData = postData.map(function(postObj, i) { postData.forEach(function(postObj, i) {
if (postObj) { if (postObj) {
postObj.index = results.indices[i]; postObj.index = results.indices[i];
postObj.deleted = parseInt(postObj.deleted, 10) === 1; postObj.deleted = parseInt(postObj.deleted, 10) === 1;
postObj.user = _.clone(results.userData[postObj.uid]); postObj.user = parseInt(postObj.uid, 10) ? results.userData[postObj.uid] : _.clone(results.userData[postObj.uid]);
postObj.editor = postObj.editor ? results.editors[postObj.editor] : null; postObj.editor = postObj.editor ? results.editors[postObj.editor] : null;
postObj.favourited = results.favourites[i]; postObj.favourited = results.favourites[i];
postObj.upvoted = results.voteData.upvotes[i]; postObj.upvoted = results.voteData.upvotes[i];
@ -135,9 +135,7 @@ module.exports = function(Topics) {
postObj.user.username = postObj.handle; postObj.user.username = postObj.handle;
} }
} }
});
return postObj;
}).filter(Boolean);
callback(null, postData); callback(null, postData);
}); });

Loading…
Cancel
Save