| 
									
										
										
										
											2014-01-30 17:41:54 -05:00
										 |  |  | var	async = require('async'), | 
					
						
							|  |  |  | 	nconf = require('nconf'), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	posts = require('../posts'), | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	meta = require('../meta'), | 
					
						
							|  |  |  | 	topics = require('../topics'), | 
					
						
							|  |  |  | 	favourites = require('../favourites'), | 
					
						
							|  |  |  | 	postTools = require('../postTools'), | 
					
						
							| 
									
										
										
										
											2014-01-30 17:41:54 -05:00
										 |  |  | 	notifications = require('../notifications'), | 
					
						
							|  |  |  | 	groups = require('../groups'), | 
					
						
							| 
									
										
										
										
											2014-01-22 21:08:43 +01:00
										 |  |  | 	user = require('../user'), | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	index = require('./index'), | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	SocketPosts = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.reply = function(socket, data, callback) { | 
					
						
							| 
									
										
										
										
											2014-02-22 17:56:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) { | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 		socket.emit('event:alert', { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 			title: 'Reply Unsuccessful', | 
					
						
							|  |  |  | 			message: 'You don't seem to be logged in, so you cannot reply.', | 
					
						
							|  |  |  | 			type: 'danger', | 
					
						
							|  |  |  | 			timeout: 2000 | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-01-27 20:21:14 -05:00
										 |  |  | 		return callback(new Error('not-logged-in')); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 	if(!data || !data.tid || !data.content) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 		return callback(new Error('invalid data')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 17:56:13 -05:00
										 |  |  | 	data.uid = socket.uid; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	topics.reply(data, function(err, postData) { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 		if(err) { | 
					
						
							|  |  |  | 			if (err.message === 'content-too-short') { | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 				module.parent.exports.emitContentTooShortAlert(socket); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 			} else if (err.message === 'too-many-posts') { | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 				module.parent.exports.emitTooManyPostsAlert(socket); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 			} else if (err.message === 'reply-error') { | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 				socket.emit('event:alert', { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 					title: 'Reply Unsuccessful', | 
					
						
							|  |  |  | 					message: 'Your reply could not be posted at this time. Please try again later.', | 
					
						
							|  |  |  | 					type: 'warning', | 
					
						
							|  |  |  | 					timeout: 2000 | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else if (err.message === 'no-privileges') { | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 				socket.emit('event:alert', { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 					title: 'Unable to post', | 
					
						
							|  |  |  | 					message: 'You do not have posting privileges in this category.', | 
					
						
							|  |  |  | 					type: 'danger', | 
					
						
							|  |  |  | 					timeout: 7500 | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 			return callback(err); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (postData) { | 
					
						
							| 
									
										
										
										
											2014-01-11 16:15:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 			module.parent.exports.emitTopicPostStats(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 			socket.emit('event:alert', { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 				title: 'Reply Successful', | 
					
						
							|  |  |  | 				message: 'You have successfully replied. Click here to view your reply.', | 
					
						
							|  |  |  | 				type: 'success', | 
					
						
							|  |  |  | 				timeout: 2000 | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			var socketData = { | 
					
						
							|  |  |  | 				posts: [postData] | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 			index.server.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData); | 
					
						
							|  |  |  | 			index.server.sockets.in('recent_posts').emit('event:new_post', socketData); | 
					
						
							|  |  |  | 			index.server.sockets.in('user/' + postData.uid).emit('event:new_post', socketData); | 
					
						
							| 
									
										
										
										
											2014-01-11 16:15:50 -05:00
										 |  |  | 			callback(); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 12:44:21 -05:00
										 |  |  | SocketPosts.upvote = function(socket, data) { | 
					
						
							|  |  |  | 	if(data && data.pid && data.room_id) { | 
					
						
							|  |  |  | 		favourites.upvote(data.pid, data.room_id, socket.uid, socket); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SocketPosts.downvote = function(socket, data) { | 
					
						
							|  |  |  | 	if(data && data.pid && data.room_id) { | 
					
						
							|  |  |  | 		favourites.downvote(data.pid, data.room_id, socket.uid, socket); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SocketPosts.unvote = function(socket, data) { | 
					
						
							|  |  |  | 	if(data && data.pid && data.room_id) { | 
					
						
							|  |  |  | 		favourites.unvote(data.pid, data.room_id, socket.uid, socket); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.favourite = function(socket, data) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	if(data && data.pid && data.room_id) { | 
					
						
							|  |  |  | 		favourites.favourite(data.pid, data.room_id, socket.uid, socket); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.unfavourite = function(socket, data) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	if(data && data.pid && data.room_id) { | 
					
						
							|  |  |  | 		favourites.unfavourite(data.pid, data.room_id, socket.uid, socket); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.uploadImage = function(socket, data, callback) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	if(data) { | 
					
						
							|  |  |  | 		posts.uploadPostImage(data, callback); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.uploadFile = function(socket, data, callback) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	if(data) { | 
					
						
							|  |  |  | 		posts.uploadPostFile(data, callback); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | SocketPosts.getRawPost = function(socket, pid, callback) { | 
					
						
							| 
									
										
										
										
											2014-01-25 22:19:51 -05:00
										 |  |  | 	posts.getPostFields(pid, ['content', 'deleted'], function(err, data) { | 
					
						
							|  |  |  | 		if(err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(data.deleted === '1') { | 
					
						
							|  |  |  | 			return callback(new Error('This post no longer exists')); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		callback(null, data.content); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.edit = function(socket, data, callback) { | 
					
						
							|  |  |  | 	if(!socket.uid) { | 
					
						
							|  |  |  | 		socket.emit('event:alert', { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 			title: 'Can't edit', | 
					
						
							|  |  |  | 			message: 'Guests can't edit posts!', | 
					
						
							|  |  |  | 			type: 'warning', | 
					
						
							|  |  |  | 			timeout: 2000 | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-01-23 15:46:39 -05:00
										 |  |  | 		return callback(new Error('not-logged-in')); | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	} else if(!data || !data.pid || !data.title || !data.content) { | 
					
						
							|  |  |  | 		return callback(new Error('invalid data')); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	} else if (!data.title || data.title.length < parseInt(meta.config.minimumTitleLength, 10)) { | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 		topics.emitTitleTooShortAlert(socket); | 
					
						
							| 
									
										
										
										
											2014-01-23 15:46:39 -05:00
										 |  |  | 		return callback(new Error('title-too-short')); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	} else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) { | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 		module.parent.exports.emitContentTooShortAlert(socket); | 
					
						
							| 
									
										
										
										
											2014-01-23 15:46:39 -05:00
										 |  |  | 		return callback(new Error('content-too-short')); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-20 02:05:49 -05:00
										 |  |  | 	postTools.edit(socket.uid, data.pid, data.title, data.content, {topic_thumb: data.topic_thumb}); | 
					
						
							| 
									
										
										
										
											2014-01-11 16:15:50 -05:00
										 |  |  | 	callback(); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.delete = function(socket, data, callback) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	if(!data) { | 
					
						
							|  |  |  | 		return callback(new Error('invalid data')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 	postTools.delete(socket.uid, data.pid, function(err) { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		module.parent.exports.emitTopicPostStats(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 		index.server.sockets.in('topic_' + data.tid).emit('event:post_deleted', { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 			pid: data.pid | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 		callback(); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.restore = function(socket, data, callback) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	if(!data) { | 
					
						
							|  |  |  | 		return callback(new Error('invalid data')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | 	postTools.restore(socket.uid, data.pid, function(err) { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 		if(err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		module.parent.exports.emitTopicPostStats(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 		index.server.sockets.in('topic_' + data.tid).emit('event:post_restored', { | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 			pid: data.pid | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		callback(); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:34:43 -05:00
										 |  |  | SocketPosts.getPrivileges = function(socket, pid, callback) { | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 	postTools.privileges(pid, socket.uid, function(err, privileges) { | 
					
						
							|  |  |  | 		if(err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 		privileges.pid = parseInt(pid); | 
					
						
							| 
									
										
										
										
											2014-01-16 22:06:23 -05:00
										 |  |  | 		callback(null, privileges); | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 21:08:43 +01:00
										 |  |  | SocketPosts.getFavouritedUsers = function(socket, pid, callback) { | 
					
						
							| 
									
										
										
										
											2014-01-24 12:11:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 21:08:43 +01:00
										 |  |  | 	favourites.getFavouritedUidsByPids([pid], function(data) { | 
					
						
							|  |  |  | 		var max = 5; //hardcoded
 | 
					
						
							|  |  |  | 		var usernames = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var pid_uids = data[pid]; | 
					
						
							|  |  |  | 		var rest_amount = 0; | 
					
						
							|  |  |  | 		if (data.hasOwnProperty(pid) && pid_uids.length > 0) { | 
					
						
							|  |  |  | 			if (pid_uids.length > max) { | 
					
						
							|  |  |  | 				rest_amount = pid_uids.length - max; | 
					
						
							|  |  |  | 				pid_uids = pid_uids.slice(0, max); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-11 23:14:41 -05:00
										 |  |  | 			user.getUsernamesByUids(pid_uids, function(err, result) { | 
					
						
							|  |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 21:08:43 +01:00
										 |  |  | 				usernames = result.join(', ') + (rest_amount > 0 | 
					
						
							|  |  |  | 					? " and " + rest_amount + (rest_amount > 1 ? " others" : " other") | 
					
						
							|  |  |  | 					: ""); | 
					
						
							|  |  |  | 				callback(null, usernames); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			callback(null, ""); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-25 19:19:25 -05:00
										 |  |  | SocketPosts.getPidPage = function(socket, pid, callback) { | 
					
						
							| 
									
										
										
										
											2014-02-10 22:45:52 -05:00
										 |  |  | 	posts.getPidPage(pid, socket.uid, callback); | 
					
						
							| 
									
										
										
										
											2014-01-25 19:19:25 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 20:57:12 -05:00
										 |  |  | SocketPosts.getPidIndex = function(socket, pid, callback) { | 
					
						
							|  |  |  | 	posts.getPidIndex(pid, callback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 17:41:54 -05:00
										 |  |  | SocketPosts.flag = function(socket, pid, callback) { | 
					
						
							| 
									
										
										
										
											2014-02-01 23:14:44 -05:00
										 |  |  | 	if (!socket.uid) { | 
					
						
							|  |  |  | 		return callback(new Error('not-logged-in')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 17:41:54 -05:00
										 |  |  | 	var message = '', | 
					
						
							|  |  |  | 		path = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function(next) { | 
					
						
							|  |  |  | 			user.getUserField(socket.uid, 'username', next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function(username, next) { | 
					
						
							|  |  |  | 			message = username + ' flagged a post.'; | 
					
						
							|  |  |  | 			posts.getPostField(pid, 'tid', next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function(tid, next) { | 
					
						
							|  |  |  | 			topics.getTopicField(tid, 'slug', next) | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function(topicSlug, next) { | 
					
						
							|  |  |  | 			path = nconf.get('relative_path') + '/topic/' + topicSlug + '#' + pid; | 
					
						
							|  |  |  | 			groups.getByGroupName('administrators', {}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function(adminGroup, next) { | 
					
						
							| 
									
										
										
										
											2014-02-15 14:52:59 -05:00
										 |  |  | 			notifications.create({ | 
					
						
							|  |  |  | 				text: message, | 
					
						
							|  |  |  | 				path: path, | 
					
						
							| 
									
										
										
										
											2014-02-15 15:43:44 -05:00
										 |  |  | 				uniqueId: 'post_flag:' + pid, | 
					
						
							|  |  |  | 				from: socket.uid | 
					
						
							| 
									
										
										
										
											2014-02-15 14:52:59 -05:00
										 |  |  | 			}, function(nid) { | 
					
						
							| 
									
										
										
										
											2014-01-30 17:41:54 -05:00
										 |  |  | 				notifications.push(nid, adminGroup.members, function() { | 
					
						
							|  |  |  | 					next(null); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-03 19:24:27 -05:00
										 |  |  | SocketPosts.loadMoreFavourites = function(socket, data, callback) { | 
					
						
							|  |  |  | 	if(!data || !data.after) { | 
					
						
							|  |  |  | 		return callback(new Error('invalid data')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var start = parseInt(data.after, 10), | 
					
						
							|  |  |  | 		end = start + 9; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	posts.getFavourites(socket.uid, start, end, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 17:31:05 -05:00
										 |  |  | SocketPosts.loadMoreUserPosts = function(socket, data, callback) { | 
					
						
							|  |  |  | 	if(!data || !data.after || !data.uid) { | 
					
						
							|  |  |  | 		return callback(new Error('invalid data')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var start = parseInt(data.after, 10), | 
					
						
							|  |  |  | 		end = start + 9; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	posts.getPostsByUid(socket.uid, data.uid, start, end, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-10 16:00:03 -05:00
										 |  |  | module.exports = SocketPosts; |