From d229cd21b2589ea18ad5830c704647c978672250 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 21 Jun 2014 01:14:49 -0400 Subject: [PATCH] parsing the post content that's passed into bodyLong in notifs #1720 --- src/socket.io/posts.js | 28 ++++++++++++++++++---------- src/topics/follow.js | 10 +++++++++- src/user/notifications.js | 10 +++++++++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 7c68e8429c..1980d21927 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -100,14 +100,16 @@ function sendNotificationToPostOwner(data, uid, notification) { } async.parallel({ - username: function(next) { - user.getUserField(uid, 'username', next); - }, - topicData: function(next) { - topics.getTopicFields(postData.tid, ['slug', 'content'], next); - }, - index: function(next) { - posts.getPidIndex(data.pid, next); + username: async.apply(user.getUserField, uid, 'username'), + slug: async.apply(topics.getTopicField, postData.tid, 'slug'), + index: async.apply(posts.getPidIndex, data.pid), + postContent: function(next) { + async.waterfall([ + async.apply(posts.getPostField, data.pid, 'content'), + function(content, next) { + postTools.parse(content, next); + } + ], next); } }, function(err, results) { if (err) { @@ -116,8 +118,8 @@ function sendNotificationToPostOwner(data, uid, notification) { notifications.create({ bodyShort: '[[' + notification + ', ' + results.username + ']]', - bodyLong: results.topicData.content, - path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.index, + bodyLong: results.postContent, + path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index, uniqueId: 'post:' + data.pid, from: uid }, function(nid) { @@ -293,6 +295,12 @@ SocketPosts.flag = function(socket, pid, callback) { message = '[[notifications:user_flagged_post, ' + username + ']]'; posts.getPostFields(pid, ['tid', 'uid', 'content'], next); }, + function(postData, next) { + postTools.parse(postData.content, function(err, parsed) { + postData.content = parsed; + next(undefined, postData); + }); + }, function(postData, next) { post = postData; topics.getTopicField(postData.tid, 'slug', next); diff --git a/src/topics/follow.js b/src/topics/follow.js index ac08f3fd59..644dde717c 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -7,6 +7,7 @@ var async = require('async'), db = require('../database'), user = require('../user'), posts = require('../posts'), + postTools = require('../postTools'), notifications = require('../notifications'); module.exports = function(Topics) { @@ -27,7 +28,14 @@ module.exports = function(Topics) { topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']), username: async.apply(user.getUserField, exceptUid, 'username'), postIndex: async.apply(posts.getPidIndex, pid), - postContent: async.apply(posts.getPostField, pid, 'content') + postContent: function(next) { + async.waterfall([ + async.apply(posts.getPostField, pid, 'content'), + function(content, next) { + postTools.parse(content, next); + } + ], next); + } }, function(err, results) { if (err) { return next(err); diff --git a/src/user/notifications.js b/src/user/notifications.js index 935ec26cd4..b1635d3427 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -10,6 +10,7 @@ var async = require('async'), db = require('../database'), notifications = require('../notifications'), posts = require('../posts'), + postTools = require('../postTools'), topics = require('../topics'); (function(UserNotifications) { @@ -156,7 +157,14 @@ var async = require('async'), username: async.apply(user.getUserField, uid, 'username'), slug: async.apply(topics.getTopicField, tid, 'slug'), postIndex: async.apply(posts.getPidIndex, pid), - postContent: async.apply(posts.getPostField, pid, 'content') + postContent: function(next) { + async.waterfall([ + async.apply(posts.getPostField, pid, 'content'), + function(content, next) { + postTools.parse(content, next); + } + ], next); + } }, function(err, results) { if (err) { return;