mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	cleanup
This commit is contained in:
		| @@ -424,6 +424,6 @@ var db = require('./database'), | ||||
|  | ||||
| 			Categories.addActiveUser(cid, uid, timestamp); | ||||
| 		}); | ||||
| 	} | ||||
| 	}; | ||||
|  | ||||
| }(exports)); | ||||
| @@ -153,24 +153,13 @@ var async = require('async'), | ||||
| 			downvoted: function(next) { | ||||
| 				db.isSetMember('pid:' + pid + ':downvote', uid, next); | ||||
| 			} | ||||
| 		}, function(err, results) { | ||||
| 			callback(err, results) | ||||
| 		}); | ||||
| 		}, callback); | ||||
| 	}; | ||||
|  | ||||
| 	Favourites.getVoteStatusByPostIDs = function(pids, uid, callback) { | ||||
| 		var data = {}; | ||||
|  | ||||
| 		function iterator(pid, next) { | ||||
| 			Favourites.hasVoted(pid, uid, function(err, voteStatus) { | ||||
| 				data[pid] = voteStatus; | ||||
| 				next() | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		async.each(pids, iterator, function(err) { | ||||
| 			callback(data); | ||||
| 		}); | ||||
| 		async.map(pids, function(pid, next) { | ||||
| 			Favourites.hasVoted(pid, uid, next); | ||||
| 		}, callback); | ||||
| 	}; | ||||
|  | ||||
| 	Favourites.favourite = function (pid, room_id, uid, socket) { | ||||
| @@ -248,33 +237,15 @@ var async = require('async'), | ||||
| 	}; | ||||
|  | ||||
| 	Favourites.getFavouritesByPostIDs = function(pids, uid, callback) { | ||||
| 		var data = {}; | ||||
|  | ||||
| 		function iterator(pid, next) { | ||||
| 			Favourites.hasFavourited(pid, uid, function(err, hasFavourited) { | ||||
| 				data[pid] = hasFavourited; | ||||
| 				next() | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		async.each(pids, iterator, function(err) { | ||||
| 			callback(data); | ||||
| 		}); | ||||
| 		async.map(pids, function(pid, next) { | ||||
| 			Favourites.hasFavourited(pid, uid, next); | ||||
| 		}, callback); | ||||
| 	}; | ||||
|  | ||||
| 	Favourites.getFavouritedUidsByPids = function(pids, callback) { | ||||
| 		var data = {}; | ||||
|  | ||||
| 		function getUids(pid, next) { | ||||
| 			db.getSetMembers('pid:' + pid + ':users_favourited', function(err, uids) { | ||||
| 				data[pid] = uids; | ||||
| 				next(); | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		async.each(pids, getUids, function(err) { | ||||
| 			callback(data); | ||||
| 		}); | ||||
| 		async.map(pids, function(pid, next) { | ||||
| 			db.getSetMembers('pid:' + pid + ':users_favourited', next); | ||||
| 		}, callback) | ||||
| 	}; | ||||
|  | ||||
| }(exports)); | ||||
| @@ -207,17 +207,28 @@ SocketPosts.getPrivileges = function(socket, pid, callback) { | ||||
|  | ||||
| SocketPosts.getFavouritedUsers = function(socket, pid, callback) { | ||||
|  | ||||
| 	favourites.getFavouritedUidsByPids([pid], function(data) { | ||||
| 	favourites.getFavouritedUidsByPids([pid], function(err, data) { | ||||
|  | ||||
| 		if(err) { | ||||
| 			return callback(err); | ||||
| 		} | ||||
|  | ||||
| 		if(!Array.isArray(data) || !data.length) { | ||||
| 			callback(null, ""); | ||||
| 		} | ||||
|  | ||||
| 		console.log(data); | ||||
| 		var max = 5; //hardcoded | ||||
| 		var usernames = ""; | ||||
|  | ||||
| 		var pid_uids = data[pid]; | ||||
| 		var pid_uids = data[0]; | ||||
| 		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); | ||||
| 		} | ||||
|  | ||||
| 		user.getUsernamesByUids(pid_uids, function(err, result) { | ||||
| 			if(err) { | ||||
| 				return callback(err); | ||||
| @@ -228,9 +239,6 @@ SocketPosts.getFavouritedUsers = function(socket, pid, callback) { | ||||
| 				: ""); | ||||
| 			callback(null, usernames); | ||||
| 		}); | ||||
| 		} else { | ||||
| 			callback(null, ""); | ||||
| 		} | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -350,12 +350,7 @@ var async = require('async'), | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
| 	Topics.getTopicPosts = function(tid, start, end, current_user, reverse, callback) { | ||||
| 		if (typeof reverse === 'function') { | ||||
| 			callback = reverse; | ||||
| 			reverse = false; | ||||
| 		} | ||||
|  | ||||
| 	Topics.getTopicPosts = function(tid, start, end, uid, reverse, callback) { | ||||
| 		posts.getPostsByTid(tid, start, end, reverse, function(err, postData) { | ||||
| 			if(err) { | ||||
| 				return callback(err); | ||||
| @@ -373,65 +368,34 @@ var async = require('async'), | ||||
| 				return post.pid; | ||||
| 			}); | ||||
|  | ||||
| 			function getFavouritesData(next) { | ||||
| 				favourites.getFavouritesByPostIDs(pids, current_user, function(fav_data) { | ||||
| 					next(null, fav_data); | ||||
| 				}); | ||||
| 			async.parallel({ | ||||
| 				favourites : function(next) { | ||||
| 					favourites.getFavouritesByPostIDs(pids, uid, next); | ||||
| 				}, | ||||
| 				voteData : function(next) { | ||||
| 					favourites.getVoteStatusByPostIDs(pids, uid, next); | ||||
| 				}, | ||||
| 				userData : function(next) { | ||||
| 					async.each(postData, posts.addUserInfoToPost, next); | ||||
| 				}, | ||||
| 				privileges : function(next) { | ||||
| 					async.map(pids, function (pid, next) { | ||||
| 						postTools.privileges(pid, uid, next); | ||||
| 					}, next); | ||||
| 				} | ||||
|  | ||||
| 			function getVoteStatusData(next) { | ||||
| 				favourites.getVoteStatusByPostIDs(pids, current_user, function(vote_data) { | ||||
| 					next(null, vote_data); | ||||
| 				}) | ||||
| 			} | ||||
|  | ||||
| 			function addUserInfoToPosts(next) { | ||||
| 				function iterator(post, callback) { | ||||
| 					posts.addUserInfoToPost(post, function() { | ||||
| 						callback(null); | ||||
| 					}); | ||||
| 				} | ||||
|  | ||||
| 				async.each(postData, iterator, function(err) { | ||||
| 					next(err, null); | ||||
| 				}); | ||||
| 			} | ||||
|  | ||||
| 			function getPrivileges(next) { | ||||
| 				var privs = {}; | ||||
| 				async.each(pids, getPostPrivileges, function(err) { | ||||
| 					next(err, privs); | ||||
| 				}); | ||||
|  | ||||
| 				function getPostPrivileges(pid, next) { | ||||
| 					postTools.privileges(pid, current_user, function(err, postPrivileges) { | ||||
| 						if(err) { | ||||
| 							return next(err); | ||||
| 						} | ||||
| 						privs[pid] = postPrivileges; | ||||
| 						next(); | ||||
| 					}); | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges, getVoteStatusData], function(err, results) { | ||||
| 			}, function(err, results) { | ||||
| 				if(err) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
|  | ||||
| 				var fav_data = results[0], | ||||
| 					privileges = results[2], | ||||
| 					voteStatus = results[3]; | ||||
|  | ||||
| 				for (var i = 0; i < postData.length; ++i) { | ||||
| 					var pid = postData[i].pid; | ||||
| 					postData[i].favourited = fav_data[pid]; | ||||
| 					postData[i].upvoted = voteStatus[pid].upvoted; | ||||
| 					postData[i].downvoted = voteStatus[pid].downvoted; | ||||
| 					postData[i].favourited = results.favourites[i]; | ||||
| 					postData[i].upvoted = results.voteData[i].upvoted; | ||||
| 					postData[i].downvoted = results.voteData[i].downvoted; | ||||
| 					postData[i].votes = postData[i].votes || 0; | ||||
| 					postData[i].display_moderator_tools = (current_user != 0) && privileges[pid].editable; | ||||
| 					postData[i].display_move_tools = privileges[pid].move; | ||||
| 					if(parseInt(postData[i].deleted, 10) === 1 && !privileges[pid].view_deleted) { | ||||
| 					postData[i].display_moderator_tools = (uid != 0) && results.privileges[i].editable; | ||||
| 					postData[i].display_move_tools = results.privileges[i].move; | ||||
| 					if(parseInt(postData[i].deleted, 10) === 1 && !results.privileges[i].view_deleted) { | ||||
| 						postData[i].content = 'This post is deleted!'; | ||||
| 					} | ||||
| 				} | ||||
| @@ -696,7 +660,7 @@ var async = require('async'), | ||||
| 		function isTopicVisible(topicData, topicInfo) { | ||||
| 			var deleted = parseInt(topicData.deleted, 10) !== 0; | ||||
|  | ||||
| 			return !deleted || (deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user; | ||||
| 			return !deleted || (deleted && topicInfo.privileges.view_deleted) || parseInt(topicData.uid, 10) === parseInt(current_user, 10); | ||||
| 		} | ||||
|  | ||||
| 		function loadTopic(tid, next) { | ||||
| @@ -765,7 +729,7 @@ var async = require('async'), | ||||
| 			} | ||||
|  | ||||
| 			function getTopicPosts(next) { | ||||
| 				Topics.getTopicPosts(tid, start, end, current_user, next); | ||||
| 				Topics.getTopicPosts(tid, start, end, current_user, false, next); | ||||
| 			} | ||||
|  | ||||
| 			function getPrivileges(next) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user