| 
									
										
										
										
											2014-02-28 00:14:11 -05:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | var async = require('async'); | 
					
						
							|  |  |  | var _ = require('underscore'); | 
					
						
							| 
									
										
										
										
											2014-06-12 16:45:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | var db = require('./database'); | 
					
						
							|  |  |  | var utils = require('../public/src/utils'); | 
					
						
							|  |  |  | var user = require('./user'); | 
					
						
							|  |  |  | var topics = require('./topics'); | 
					
						
							|  |  |  | var privileges = require('./privileges'); | 
					
						
							|  |  |  | var plugins = require('./plugins'); | 
					
						
							| 
									
										
										
										
											2013-05-09 01:04:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | (function (Posts) { | 
					
						
							| 
									
										
										
										
											2014-11-09 01:12:24 -05:00
										 |  |  | 	require('./posts/create')(Posts); | 
					
						
							| 
									
										
										
										
											2014-06-09 12:51:49 -04:00
										 |  |  | 	require('./posts/delete')(Posts); | 
					
						
							| 
									
										
										
										
											2015-04-20 17:56:43 -04:00
										 |  |  | 	require('./posts/edit')(Posts); | 
					
						
							|  |  |  | 	require('./posts/parse')(Posts); | 
					
						
							| 
									
										
										
										
											2014-11-09 01:12:24 -05:00
										 |  |  | 	require('./posts/user')(Posts); | 
					
						
							| 
									
										
										
										
											2015-03-09 13:16:14 -04:00
										 |  |  | 	require('./posts/topics')(Posts); | 
					
						
							| 
									
										
										
										
											2014-11-09 01:12:24 -05:00
										 |  |  | 	require('./posts/category')(Posts); | 
					
						
							|  |  |  | 	require('./posts/summary')(Posts); | 
					
						
							|  |  |  | 	require('./posts/recent')(Posts); | 
					
						
							| 
									
										
										
										
											2014-10-07 16:21:12 -04:00
										 |  |  | 	require('./posts/flags')(Posts); | 
					
						
							| 
									
										
										
										
											2015-09-17 14:58:58 -04:00
										 |  |  | 	require('./posts/tools')(Posts); | 
					
						
							| 
									
										
										
										
											2016-10-08 19:09:48 +03:00
										 |  |  | 	require('./posts/votes')(Posts); | 
					
						
							|  |  |  | 	require('./posts/bookmarks')(Posts); | 
					
						
							| 
									
										
										
										
											2014-06-09 12:51:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.exists = function (pid, callback) { | 
					
						
							| 
									
										
										
										
											2014-10-31 22:04:09 -04:00
										 |  |  | 		db.isSortedSetMember('posts:pid', pid, callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPidsFromSet = function (set, start, stop, reverse, callback) { | 
					
						
							| 
									
										
										
										
											2015-03-31 23:40:58 -04:00
										 |  |  | 		if (isNaN(start) || isNaN(stop)) { | 
					
						
							| 
									
										
										
										
											2014-09-06 20:46:18 -04:00
										 |  |  | 			return callback(null, []); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-31 23:40:58 -04:00
										 |  |  | 		db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback); | 
					
						
							| 
									
										
										
										
											2014-08-12 11:19:17 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPostsByPids = function (pids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2015-05-11 15:38:14 -04:00
										 |  |  | 		if (!Array.isArray(pids) || !pids.length) { | 
					
						
							|  |  |  | 			return callback(null, []); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 21:00:10 -05:00
										 |  |  | 		var keys = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 01:12:18 -07:00
										 |  |  | 		for (var x = 0, numPids = pids.length; x < numPids; x += 1) { | 
					
						
							| 
									
										
										
										
											2014-01-20 21:00:10 -05:00
										 |  |  | 			keys.push('post:' + pids[x]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 		async.waterfall([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 				db.getObjects(keys, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (posts, next) { | 
					
						
							|  |  |  | 				async.map(posts, function (post, next) { | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 					if (!post) { | 
					
						
							|  |  |  | 						return next(); | 
					
						
							| 
									
										
										
										
											2014-08-12 11:19:17 -04:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-06-13 14:02:54 +03:00
										 |  |  | 					post.upvotes = parseInt(post.upvotes, 10) || 0; | 
					
						
							|  |  |  | 					post.downvotes = parseInt(post.downvotes, 10) || 0; | 
					
						
							|  |  |  | 					post.votes = post.upvotes - post.downvotes; | 
					
						
							| 
									
										
										
										
											2016-03-03 20:13:30 +02:00
										 |  |  | 					post.timestampISO = utils.toISOString(post.timestamp); | 
					
						
							|  |  |  | 					post.editedISO = parseInt(post.edited, 10) !== 0 ? utils.toISOString(post.edited) : ''; | 
					
						
							| 
									
										
										
										
											2015-04-20 17:56:43 -04:00
										 |  |  | 					Posts.parsePost(post, next); | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 				}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (posts, next) { | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 				plugins.fireHook('filter:post.getPosts', {posts: posts, uid: uid}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (data, next) { | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 				if (!data || !Array.isArray(data.posts)) { | 
					
						
							|  |  |  | 					return next(null, []); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				data.posts = data.posts.filter(Boolean); | 
					
						
							|  |  |  | 				next(null, data.posts); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-01-20 21:00:10 -05:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPostSummariesFromSet = function (set, uid, start, stop, callback) { | 
					
						
							| 
									
										
										
										
											2014-11-19 11:02:28 -05:00
										 |  |  | 		async.waterfall([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2015-03-31 23:40:58 -04:00
										 |  |  | 				db.getSortedSetRevRange(set, start, stop, next); | 
					
						
							| 
									
										
										
										
											2014-11-19 11:02:28 -05:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (pids, next) { | 
					
						
							| 
									
										
										
										
											2014-11-19 11:02:28 -05:00
										 |  |  | 				privileges.posts.filter('read', pids, uid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (pids, next) { | 
					
						
							| 
									
										
										
										
											2014-11-19 11:02:28 -05:00
										 |  |  | 				Posts.getPostSummaryByPids(pids, uid, {stripTags: false}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (posts, next) { | 
					
						
							| 
									
										
										
										
											2015-03-31 23:40:58 -04:00
										 |  |  | 				next(null, {posts: posts, nextStart: stop + 1}); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2014-11-19 11:02:28 -05:00
										 |  |  | 		], callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPostData = function (pid, callback) { | 
					
						
							|  |  |  | 		db.getObject('post:' + pid, function (err, data) { | 
					
						
							| 
									
										
										
										
											2015-04-07 14:15:35 -04:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-02-08 13:44:15 -05:00
										 |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2013-11-03 11:53:44 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-11-15 13:39:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 13:44:15 -05:00
										 |  |  | 			plugins.fireHook('filter:post.get', data, callback); | 
					
						
							| 
									
										
										
										
											2013-07-02 16:24:13 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-21 19:42:07 -05:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-24 12:46:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPostField = function (pid, field, callback) { | 
					
						
							|  |  |  | 		Posts.getPostFields(pid, [field], function (err, data) { | 
					
						
							| 
									
										
										
										
											2014-11-11 18:08:03 -05:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			callback(null, data[field]); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPostFields = function (pid, fields, callback) { | 
					
						
							|  |  |  | 		db.getObjectFields('post:' + pid, fields, function (err, data) { | 
					
						
							| 
									
										
										
										
											2014-11-11 18:05:42 -05:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-02-08 13:44:15 -05:00
										 |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2013-07-22 17:08:07 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-11-15 14:57:50 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			data.pid = pid; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			plugins.fireHook('filter:post.getFields', {posts: [data], fields: fields}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2014-11-11 18:34:29 -05:00
										 |  |  | 				callback(err, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-21 19:42:07 -05:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-07-02 19:46:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPostsFields = function (pids, fields, callback) { | 
					
						
							| 
									
										
										
										
											2014-10-02 19:03:03 -04:00
										 |  |  | 		if (!Array.isArray(pids) || !pids.length) { | 
					
						
							|  |  |  | 			return callback(null, []); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-10-02 16:00:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		var keys = pids.map(function (pid) { | 
					
						
							| 
									
										
										
										
											2014-06-28 14:59:01 -04:00
										 |  |  | 			return 'post:' + pid; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		db.getObjectsFields(keys, fields, function (err, posts) { | 
					
						
							| 
									
										
										
										
											2014-11-11 18:08:03 -05:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-02-08 13:44:15 -05:00
										 |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2013-10-22 14:22:16 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			plugins.fireHook('filter:post.getFields', {posts: posts, fields: fields}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2014-11-20 00:10:08 -05:00
										 |  |  | 				callback(err, (data && Array.isArray(data.posts)) ? data.posts : null); | 
					
						
							| 
									
										
										
										
											2014-11-11 18:34:29 -05:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-08-09 20:03:19 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-21 19:42:07 -05:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-08-09 20:03:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.setPostField = function (pid, field, value, callback) { | 
					
						
							|  |  |  | 		db.setObjectField('post:' + pid, field, value, function (err) { | 
					
						
							| 
									
										
										
										
											2014-11-11 18:13:15 -05:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var data = { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				pid: pid, | 
					
						
							| 
									
										
										
										
											2014-11-11 18:13:15 -05:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 			data[field] = value; | 
					
						
							| 
									
										
										
										
											2014-11-11 18:14:45 -05:00
										 |  |  | 			plugins.fireHook('action:post.setFields', data); | 
					
						
							| 
									
										
										
										
											2014-11-11 18:13:15 -05:00
										 |  |  | 			callback(); | 
					
						
							| 
									
										
										
										
											2013-11-27 15:03:36 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-21 19:42:07 -05:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.setPostFields = function (pid, data, callback) { | 
					
						
							|  |  |  | 		db.setObject('post:' + pid, data, function (err) { | 
					
						
							| 
									
										
										
										
											2014-11-11 18:13:15 -05:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			data.pid = pid; | 
					
						
							| 
									
										
										
										
											2014-11-11 18:14:45 -05:00
										 |  |  | 			plugins.fireHook('action:post.setFields', data); | 
					
						
							| 
									
										
										
										
											2014-11-11 18:13:15 -05:00
										 |  |  | 			callback(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-21 19:42:07 -05:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-08-09 20:03:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPidIndex = function (pid, tid, topicPostSort, callback) { | 
					
						
							| 
									
										
										
										
											2015-09-14 21:04:56 -04:00
										 |  |  | 		var set = topicPostSort === 'most_votes' ? 'tid:' + tid + ':posts:votes' : 'tid:' + tid + ':posts'; | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		db.sortedSetRank(set, pid, function (err, index) { | 
					
						
							| 
									
										
										
										
											2015-09-14 21:04:56 -04:00
										 |  |  | 			if (!utils.isNumber(index)) { | 
					
						
							|  |  |  | 				return callback(err, 0); | 
					
						
							| 
									
										
										
										
											2014-02-17 20:57:12 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-14 21:04:56 -04:00
										 |  |  | 			callback(err, parseInt(index, 10) + 1); | 
					
						
							| 
									
										
										
										
											2014-02-17 20:57:12 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-02-28 00:14:11 -05:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-01-25 19:19:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.getPostIndices = function (posts, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-09-21 13:30:20 -04:00
										 |  |  | 		if (!Array.isArray(posts) || !posts.length) { | 
					
						
							|  |  |  | 			return callback(null, []); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-09-26 22:19:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				user.getSettings(uid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (settings, next) { | 
					
						
							|  |  |  | 				var byVotes = settings.topicPostSort === 'most_votes'; | 
					
						
							|  |  |  | 				var sets = posts.map(function (post) { | 
					
						
							|  |  |  | 					return byVotes ? 'tid:' + post.tid + ':posts:votes' : 'tid:' + post.tid + ':posts'; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var uniqueSets = _.uniq(sets); | 
					
						
							|  |  |  | 				var method = 'sortedSetsRanks'; | 
					
						
							|  |  |  | 				if (uniqueSets.length === 1) { | 
					
						
							|  |  |  | 					method = 'sortedSetRanks'; | 
					
						
							|  |  |  | 					sets = uniqueSets[0]; | 
					
						
							| 
									
										
										
										
											2014-08-16 21:33:42 -04:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 				var pids = posts.map(function (post) { | 
					
						
							|  |  |  | 					return post.pid; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				db[method](sets, pids, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (indices, next) { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:12:18 -07:00
										 |  |  | 				for (var i = 0; i < indices.length; i += 1) { | 
					
						
							| 
									
										
										
										
											2014-08-16 21:33:42 -04:00
										 |  |  | 					indices[i] = utils.isNumber(indices[i]) ? parseInt(indices[i], 10) + 1 : 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 				next(null, indices); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-08-16 21:33:42 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	Posts.updatePostVoteCount = function (postData, callback) { | 
					
						
							| 
									
										
										
										
											2016-01-14 13:47:26 +02:00
										 |  |  | 		if (!postData || !postData.pid || !postData.tid) { | 
					
						
							|  |  |  | 			return callback(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-06 22:12:14 -04:00
										 |  |  | 		async.parallel([ | 
					
						
							| 
									
										
										
										
											2016-01-14 13:47:26 +02:00
										 |  |  | 			function (next) { | 
					
						
							|  |  |  | 				if (postData.uid) { | 
					
						
							| 
									
										
										
										
											2016-08-05 22:35:26 +03:00
										 |  |  | 					if (postData.votes > 0) { | 
					
						
							|  |  |  | 						db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						db.sortedSetRemove('uid:' + postData.uid + ':posts:votes', postData.pid, next); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-01-14 13:47:26 +02:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					next(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				async.waterfall([ | 
					
						
							|  |  |  | 					function (next) { | 
					
						
							|  |  |  | 						topics.getTopicField(postData.tid, 'mainPid', next); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					function (mainPid, next) { | 
					
						
							|  |  |  | 						if (parseInt(mainPid, 10) === parseInt(postData.pid, 10)) { | 
					
						
							| 
									
										
										
										
											2014-06-06 22:12:14 -04:00
										 |  |  | 							return next(); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2016-06-13 14:02:54 +03:00
										 |  |  | 						db.sortedSetAdd('tid:' + postData.tid + ':posts:votes', postData.votes, postData.pid, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2016-01-14 13:47:26 +02:00
										 |  |  | 				], next); | 
					
						
							| 
									
										
										
										
											2014-06-06 22:12:14 -04:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-01-14 13:47:26 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2016-06-13 14:02:54 +03:00
										 |  |  | 				Posts.setPostFields(postData.pid, {upvotes: postData.upvotes, downvotes: postData.downvotes}, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		], function (err) { | 
					
						
							| 
									
										
										
										
											2016-01-14 13:47:26 +02:00
										 |  |  | 			callback(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-06-06 22:12:14 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-05-14 17:53:23 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 13:21:51 +03:00
										 |  |  | 	Posts.modifyPostByPrivilege = function (post, isAdminOrMod) { | 
					
						
							|  |  |  | 		if (post.deleted && !(isAdminOrMod || post.selfPost)) { | 
					
						
							|  |  |  | 			post.content = '[[topic:post_is_deleted]]'; | 
					
						
							|  |  |  | 			if (post.user) { | 
					
						
							|  |  |  | 				post.user.signature = ''; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-09-21 22:47:27 -04:00
										 |  |  | }(exports)); |