mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
closed #194 - refactoring of post creation so that, normalizing post
objects also fixes julianlam/nodebb-plugin-mentions#1
This commit is contained in:
42
src/posts.js
42
src/posts.js
@@ -227,22 +227,8 @@ var RDB = require('./redis.js'),
|
||||
|
||||
threadTools.notify_followers(tid, uid);
|
||||
|
||||
postData.content = postTools.markdownToHTML(postData.content);
|
||||
postData.post_rep = 0;
|
||||
postData.relativeTime = utils.relativeTime(postData.timestamp);
|
||||
postData.fav_button_class = '';
|
||||
postData.fav_star_class = 'icon-star-empty';
|
||||
postData['edited-class'] = 'none';
|
||||
postData.show_banned = 'hide';
|
||||
postData.uploadedImages = JSON.parse(postData.uploadedImages);
|
||||
|
||||
var socketData = {
|
||||
'posts' : [
|
||||
postData
|
||||
]
|
||||
};
|
||||
|
||||
posts.addUserInfoToPost(socketData['posts'][0], function() {
|
||||
Posts.addUserInfoToPost(postData, function() {
|
||||
var socketData = { posts: [postData] };
|
||||
io.sockets.in('topic_' + tid).emit('event:new_post', socketData);
|
||||
io.sockets.in('recent_posts').emit('event:new_post', socketData);
|
||||
});
|
||||
@@ -278,7 +264,14 @@ var RDB = require('./redis.js'),
|
||||
'editor': '',
|
||||
'edited': 0,
|
||||
'deleted': 0,
|
||||
'uploadedImages': ''
|
||||
'uploadedImages': [],
|
||||
'fav_button_class': '',
|
||||
'fav_star_class': 'icon-star-empty',
|
||||
'show_banned': 'hide',
|
||||
'relativeTime': '0 seconds',
|
||||
'post_rep': '0',
|
||||
'edited-class': 'none',
|
||||
'relativeEditTime': ''
|
||||
};
|
||||
|
||||
RDB.hmset('post:' + pid, postData);
|
||||
@@ -309,13 +302,26 @@ var RDB = require('./redis.js'),
|
||||
|
||||
user.onNewPostMade(uid, tid, pid, timestamp);
|
||||
|
||||
async.parallel({
|
||||
uploadedImages: function(next) {
|
||||
uploadPostImages(postData, images, function(err, uploadedImages) {
|
||||
if(err) {
|
||||
winston.error('Uploading images failed!', err.stack);
|
||||
next(null, []);
|
||||
} else {
|
||||
postData.uploadedImages = JSON.stringify(uploadedImages);
|
||||
next(null, uploadedImages);
|
||||
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
|
||||
}
|
||||
});
|
||||
},
|
||||
content: function(next) {
|
||||
plugins.fireHook('filter:post.get', content, function(content) {
|
||||
next(null, content);
|
||||
});
|
||||
}
|
||||
}, function(err, results) {
|
||||
postData.uploadedImages = results.uploadedImages;
|
||||
postData.content = results.content;
|
||||
callback(postData);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user