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