mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
removed most of the debug
dont get more than 6 usernames for upvote tooltips generatePostPaths wont check null pids
This commit is contained in:
@@ -14,8 +14,6 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
||||
|
||||
share.addShareHandlers(topicName);
|
||||
|
||||
addFavouriteHandler();
|
||||
|
||||
addVoteHandler();
|
||||
};
|
||||
|
||||
@@ -37,12 +35,6 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
||||
});
|
||||
};
|
||||
|
||||
function addFavouriteHandler() {
|
||||
$('#post-container').on('mouseenter', '.favourite-tooltip', function() {
|
||||
loadDataAndCreateTooltip($(this), 'posts.getFavouritedUsers');
|
||||
});
|
||||
}
|
||||
|
||||
function addVoteHandler() {
|
||||
$('#post-container').on('mouseenter', '.post-row .votes', function() {
|
||||
loadDataAndCreateTooltip($(this), 'posts.getUpvoters');
|
||||
@@ -51,21 +43,21 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
|
||||
|
||||
function loadDataAndCreateTooltip(el, method) {
|
||||
var pid = el.parents('.post-row').attr('data-pid');
|
||||
socket.emit(method, pid, function(err, usernames) {
|
||||
socket.emit(method, pid, function(err, data) {
|
||||
if (!err) {
|
||||
createTooltip(el, usernames);
|
||||
createTooltip(el, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createTooltip(el, usernames) {
|
||||
function createTooltip(el, data) {
|
||||
var usernames = data.usernames;
|
||||
if (!usernames.length) {
|
||||
return;
|
||||
}
|
||||
if (usernames.length > 6) {
|
||||
var otherCount = usernames.length - 5;
|
||||
usernames = usernames.slice(0, 5).join(', ').replace(/,/g, '|');
|
||||
translator.translate('[[topic:users_and_others, ' + usernames + ', ' + otherCount + ']]', function(translated) {
|
||||
if (usernames.length + data.otherCount > 6) {
|
||||
usernames = usernames.join(', ').replace(/,/g, '|');
|
||||
translator.translate('[[topic:users_and_others, ' + usernames + ', ' + data.otherCount + ']]', function(translated) {
|
||||
translated = translated.replace(/\|/g, ',');
|
||||
el.attr('title', translated).tooltip('destroy').tooltip('show');
|
||||
});
|
||||
|
||||
@@ -109,14 +109,13 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Posts.getPidsFromSet = function(set, start, end, reverse, callback) {
|
||||
if (isNaN(start) || isNaN(end)) {
|
||||
return callback(null, []);
|
||||
}
|
||||
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, callback);
|
||||
};
|
||||
|
||||
Posts.getPostsByPids = function(pids, callback) {
|
||||
if (pids && pids.length > 100) {
|
||||
var e = new Error('getPostsByPids');
|
||||
winston.warn('[GET_POST_BY_PIDS ' + pids.length, e.stack);
|
||||
}
|
||||
var keys = [];
|
||||
|
||||
for(var x=0, numPids=pids.length; x<numPids; ++x) {
|
||||
|
||||
@@ -16,10 +16,6 @@ module.exports = function(privileges) {
|
||||
privileges.posts = {};
|
||||
|
||||
privileges.posts.get = function(pids, uid, callback) {
|
||||
if (pids && pids.length > 50) {
|
||||
var e = new Error('too many keys')
|
||||
winston.warn('[TOO_MANY_KEYS] ' + pids.length, e.stack);
|
||||
}
|
||||
async.parallel({
|
||||
manage_content: function(next) {
|
||||
helpers.hasEnoughReputationFor('privileges:manage_content', uid, next);
|
||||
|
||||
@@ -254,23 +254,22 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
|
||||
favourites.getFavouritedUidsByPids([pid], function(err, data) {
|
||||
if (err || !Array.isArray(data) || !data.length) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
user.getUsernamesByUids(data[0], callback);
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.getUpvoters = function(socket, pid, callback) {
|
||||
favourites.getUpvotedUidsByPids([pid], function(err, data) {
|
||||
if (err || !Array.isArray(data) || !data.length) {
|
||||
return callback(err, []);
|
||||
}
|
||||
|
||||
user.getUsernamesByUids(data[0], callback);
|
||||
var otherCount = 0;
|
||||
if (data[0].length > 6) {
|
||||
otherCount = data[0].length - 5;
|
||||
data[0] = data[0].slice(0, 5);
|
||||
}
|
||||
user.getUsernamesByUids(data[0], function(err, usernames) {
|
||||
callback(err, {
|
||||
otherCount: otherCount,
|
||||
usernames: usernames
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -244,10 +244,6 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Topics.getTopicWithPosts = function(tid, set, uid, start, end, reverse, callback) {
|
||||
if (isNaN(start) || isNaN(end)) {
|
||||
var e = new Error('TOO LARGE');
|
||||
winston.warn('IS_NAN_CHECK set, start, end, uid, tid', set, start, end, uid, tid, e.stack);
|
||||
}
|
||||
Topics.getTopicData(tid, function(err, topicData) {
|
||||
if (err || !topicData) {
|
||||
return callback(err || new Error('[[error:no-topic]]'));
|
||||
@@ -268,10 +264,7 @@ var async = require('async'),
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (posts.length > 100) {
|
||||
var e = new Error('TOO LARGE');
|
||||
winston.warn('GET_TOPIC_WITH_POSTS set, start, end, uid, tid', set, start, end, uid, tid, e.stack);
|
||||
}
|
||||
|
||||
Topics.addPostData(posts, uid, next);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,10 +38,6 @@ module.exports = function(Topics) {
|
||||
};
|
||||
|
||||
Topics.addPostData = function(postData, uid, callback) {
|
||||
if (postData && postData.length > 50) {
|
||||
var e = new Error('too many keys');
|
||||
winston.warn('[ADD POST DATA] ' + postData.length, e.stack);
|
||||
}
|
||||
var pids = postData.map(function(post) {
|
||||
return post && post.pid;
|
||||
});
|
||||
|
||||
@@ -135,7 +135,7 @@ var async = require('async'),
|
||||
return notification ? notification.pid : null;
|
||||
});
|
||||
|
||||
generatePostPaths(pids, uid, function(err, paths) {
|
||||
generatePostPaths(pids, uid, function(err, pidToPaths) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
notification.read = hasRead[index];
|
||||
notification.path = paths[index] || notification.path || '';
|
||||
notification.path = pidToPaths[notification.pid] || notification.path || '';
|
||||
notification.datetimeISO = utils.toISOString(notification.datetime);
|
||||
notification.readClass = !notification.read ? 'label-warning' : '';
|
||||
return notification;
|
||||
@@ -159,7 +159,7 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
function generatePostPaths(pids, uid, callback) {
|
||||
var postKeys = pids.map(function(pid) {
|
||||
var postKeys = pids.filter(Boolean).map(function(pid) {
|
||||
return 'post:' + pid;
|
||||
});
|
||||
|
||||
@@ -184,18 +184,16 @@ var async = require('async'),
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var paths = [];
|
||||
var pidToPaths = {};
|
||||
pids.forEach(function(pid, index) {
|
||||
var slug = results.topics[index] ? results.topics[index].slug : null;
|
||||
var postIndex = utils.isNumber(results.indices[index]) ? parseInt(results.indices[index], 10) + 1 : null;
|
||||
|
||||
if (slug && postIndex) {
|
||||
paths.push(nconf.get('relative_path') + '/topic/' + slug + '/' + postIndex);
|
||||
} else {
|
||||
paths.push(null);
|
||||
pidToPaths[pid] = nconf.get('relative_path') + '/topic/' + slug + '/' + postIndex;
|
||||
}
|
||||
});
|
||||
callback(null, paths);
|
||||
callback(null, pidToPaths);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user