diff --git a/src/postTools.js b/src/postTools.js index 647d796841..cb3b1da938 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -120,7 +120,7 @@ var cache = LRU({ }, postData: function(next) { cache.del(postData.pid); - PostTools.parsePost(postData, data.uid, next); + PostTools.parsePost(postData, next); } }, function(err, results) { if (err) { @@ -176,7 +176,7 @@ var cache = LRU({ if (err) { return callback(err); } - PostTools.parsePost(postData, uid, callback); + PostTools.parsePost(postData, callback); }); } }); @@ -192,7 +192,7 @@ var cache = LRU({ }); }; - PostTools.parsePost = function(postData, uid, callback) { + PostTools.parsePost = function(postData, callback) { postData.content = postData.content || ''; var cachedContent = cache.get(postData.pid); @@ -201,7 +201,7 @@ var cache = LRU({ return callback(null, postData); } - plugins.fireHook('filter:parse.post', {postData: postData, uid: uid}, function(err, data) { + plugins.fireHook('filter:parse.post', {postData: postData}, function(err, data) { if (err) { return callback(err); } diff --git a/src/posts.js b/src/posts.js index 2c7ca82737..53931d75f7 100644 --- a/src/posts.js +++ b/src/posts.js @@ -52,7 +52,7 @@ var async = require('async'), postData.relativeTime = utils.toISOString(postData.timestamp); postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? utils.toISOString(postData.edited) : ''; - postTools.parsePost(postData, uid, next); + postTools.parsePost(postData, next); }, function(err, posts) { if (err) { return callback(err); diff --git a/src/posts/summary.js b/src/posts/summary.js index 962a51aaa6..6d098cd829 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -86,7 +86,7 @@ module.exports = function(Posts) { return next(null, post); } - postTools.parsePost(post, uid, function(err, post) { + postTools.parsePost(post, function(err, post) { if (err) { return next(err); } diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index b49e796e7a..94f6be7a37 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -232,7 +232,7 @@ SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) { async.parallel({ username: async.apply(user.getUserField, fromuid, 'username'), topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'), - postObj: async.apply(postTools.parsePost, postData, postData.uid) + postObj: async.apply(postTools.parsePost, postData) }, function(err, results) { if (err) { return; @@ -479,7 +479,7 @@ SocketPosts.flag = function(socket, pid, callback) { function(topic, next) { post.topic = topic; message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topic.title + ']]'; - postTools.parsePost(post, socket.uid, next); + postTools.parsePost(post, next); }, function(post, next) { async.parallel({ diff --git a/src/topics/create.js b/src/topics/create.js index 5988f637e2..f7af1d0c5e 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -245,7 +245,7 @@ module.exports = function(Topics) { posts.getPidIndex(postData.pid, uid, next); }, content: function(next) { - postTools.parsePost(postData, uid, next); + postTools.parsePost(postData, next); } }, next); }, diff --git a/src/topics/teaser.js b/src/topics/teaser.js index adb4f77b5c..5946eef988 100644 --- a/src/topics/teaser.js +++ b/src/topics/teaser.js @@ -3,11 +3,13 @@ 'use strict'; var async = require('async'), + S = require('string'), db = require('../database'), user = require('../user'), posts = require('../posts'), plugins = require('../plugins'), + postTools = require('../postTools'), utils = require('../../public/src/utils'); @@ -49,21 +51,30 @@ module.exports = function(Topics) { users[user.uid] = user; }); var tidToPost = {}; - postData.forEach(function(post) { + + async.each(postData, function(post, next) { post.user = users[post.uid]; post.timestamp = utils.toISOString(post.timestamp); tidToPost[post.tid] = post; - }); - - var teasers = topics.map(function(topic, index) { - if (tidToPost[topic.tid]) { - tidToPost[topic.tid].index = counts[index]; + postTools.parsePost(post, next); + }, function(err) { + if (err) { + return callback(err); } - return tidToPost[topic.tid]; - }); - - plugins.fireHook('filter:teasers.get', {teasers: teasers}, function(err, data) { - callback(err, data ? data.teasers : null); + var teasers = topics.map(function(topic, index) { + if (tidToPost[topic.tid]) { + tidToPost[topic.tid].index = counts[index]; + if (tidToPost[topic.tid].content) { + var s = S(tidToPost[topic.tid].content); + tidToPost[topic.tid].content = s.stripTags.apply(s, utils.stripTags).s; + } + } + return tidToPost[topic.tid]; + }); + + plugins.fireHook('filter:teasers.get', {teasers: teasers}, function(err, data) { + callback(err, data ? data.teasers : null); + }); }); }); });