all files / src/posts/ parse.js

66.67% Statements 14/21
56.25% Branches 9/16
75% Functions 3/4
66.67% Lines 14/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44          31×   31×           31×       31× 31×       31×   31×       31×                  
 
'use strict';
 
var cache = require('./cache');
var plugins = require('../plugins');
var translator = require('../../public/src/modules/translator');
 
module.exports = function(Posts) {
 
	Posts.parsePost = function(postData, callback) {
		postData.content = postData.content || '';
 
		Iif (postData.pid && cache.has(postData.pid)) {
			postData.content = cache.get(postData.pid);
			return callback(null, postData);
		}
 
		// Casting post content into a string, just in case
		Iif (typeof postData.content !== 'string') {
			postData.content = postData.content.toString();
		}
 
		plugins.fireHook('filter:parse.post', {postData: postData}, function(err, data) {
			Iif (err) {
				return callback(err);
			}
 
			data.postData.content = translator.escape(data.postData.content);
 
			Iif (global.env === 'production' && data.postData.pid) {
				cache.set(data.postData.pid, data.postData.content);
			}
 
			callback(null, data.postData);
		});
	};
 
	Posts.parseSignature = function(userData, uid, callback) {
		userData.signature = userData.signature || '';
 
		plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
	};
};