Merge branch '0.7.0'

Conflicts:
	package.json
	src/search.js
v1.18.x
Julian Lam 10 years ago
commit 957415463f

@ -69,7 +69,7 @@ define('forum/topic/events', [
};
function updatePostVotesAndUserReputation(data) {
var votes = $('li[data-pid="' + data.post.pid + '"] .votes'),
var votes = $('[data-pid="' + data.post.pid + '"] .votes'),
reputationElements = $('.reputation[data-uid="' + data.post.uid + '"]');
votes.html(data.post.votes).attr('data-votes', data.post.votes);
@ -77,7 +77,7 @@ define('forum/topic/events', [
}
function updateFavouriteCount(data) {
$('li[data-pid="' + data.post.pid + '"] .favouriteCount').html(data.post.reputation).attr('data-favourites', data.post.reputation);
$('[data-pid="' + data.post.pid + '"] .favouriteCount').html(data.post.reputation).attr('data-favourites', data.post.reputation);
}
function toggleTopicDeleteState(data) {
@ -139,14 +139,14 @@ define('forum/topic/events', [
}
function onPostPurged(pid) {
$('#post-container li[data-pid="' + pid + '"]').fadeOut(500, function() {
$('#post-container [data-pid="' + pid + '"]').fadeOut(500, function() {
$(this).remove();
});
postTools.updatePostCount();
}
function togglePostDeleteState(data) {
var postEl = $('#post-container li[data-pid="' + data.pid + '"]');
var postEl = $('#post-container [data-pid="' + data.pid + '"]');
if (!postEl.length) {
return;
@ -166,7 +166,7 @@ define('forum/topic/events', [
}
function togglePostFavourite(data) {
var favBtn = $('li[data-pid="' + data.post.pid + '"] .favourite');
var favBtn = $('[data-pid="' + data.post.pid + '"] .favourite');
if (!favBtn.length) {
return;
}
@ -185,7 +185,7 @@ define('forum/topic/events', [
}
function togglePostVote(data) {
var post = $('li[data-pid="' + data.post.pid + '"]');
var post = $('[data-pid="' + data.post.pid + '"]');
post.find('.upvote').toggleClass('btn-primary upvoted', data.upvote);
post.find('.downvote').toggleClass('btn-primary downvoted', data.downvote);

@ -47,7 +47,7 @@ define('forum/topic/posts', [
function removeAlreadyAddedPosts() {
data.posts = data.posts.filter(function(post) {
return $('#post-container li[data-pid="' + post.pid +'"]').length === 0;
return $('#post-container [data-pid="' + post.pid +'"]').length === 0;
});
}
@ -59,8 +59,8 @@ define('forum/topic/posts', [
var firstPostVotes = parseInt(data.posts[0].votes, 10);
var firstPostIndex = parseInt(data.posts[0].index, 10);
var firstReply = $('#post-container li.post-row[data-index!="0"]').first();
var lastReply = $('#post-container li.post-row[data-index!="0"]').last();
var firstReply = $('#post-container .post-row[data-index!="0"]').first();
var lastReply = $('#post-container .post-row[data-index!="0"]').last();
if (config.topicPostSort === 'oldest_to_newest') {
if (firstPostTimestamp < parseInt(firstReply.attr('data-timestamp'), 10)) {
@ -106,7 +106,7 @@ define('forum/topic/posts', [
// Save document height and position for future reference (about 5 lines down)
var height = $(document).height(),
scrollTop = $(document).scrollTop(),
originalPostEl = $('li[data-index="0"]');
originalPostEl = $('.post-row[data-index="0"]');
// Insert the new post
html.insertBefore(before);
@ -181,7 +181,7 @@ define('forum/topic/posts', [
function loadPostsAfter(after) {
var tid = ajaxify.variables.get('topic_id');
if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="1"]').length)) {
if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container .post-row[data-index="1"]').length)) {
return;
}
@ -230,13 +230,13 @@ define('forum/topic/posts', [
};
function showBottomPostBar() {
if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) {
if($('#post-container .post-row').length > 1 || !$('#post-container [data-index="0"]').length) {
$('.bottom-post-bar').removeClass('hide');
}
}
function hidePostToolsForDeletedPosts(element) {
element.find('li.deleted').each(function() {
element.find('.post-row.deleted').each(function() {
postTools.toggle($(this).attr('data-pid'), true);
});
}

@ -115,11 +115,6 @@ define('forum/users', function() {
var username = $('#search-user').val();
var notify = $('#user-notfound-notify');
page = page || 1;
if (!username) {
notify.html('<i class="fa fa-circle-o"></i>');
notify.parent().removeClass('btn-warning label-warning btn-success label-success');
return;
}
notify.html('<i class="fa fa-spinner fa-spin"></i>');
var filters = [];

@ -21,6 +21,11 @@
return '<meta ' + name + property + content + '/>';
};
helpers.stringify = function(obj) {
// Turns the incoming object into a JSON string
return JSON.stringify(obj).replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;").replace(/"/g, '&quot;');
};
// Groups helpers
helpers.membershipBtn = function(groupObj) {
if (groupObj.isMember) {

@ -49,7 +49,7 @@ define('uploader', ['csrf'], function(csrf) {
},
error: function(xhr) {
xhr = maybeParse(xhr);
showAlert('error', xhr.responseJSON.error);
showAlert('error', xhr.responseJSON ? xhr.responseJSON.error : 'error uploading, code : ' + xhr.status);
},
uploadProgress: function(event, position, total, percent) {

@ -31,7 +31,8 @@ usersController.banned = function(req, res, next) {
};
function getUsers(set, req, res, next) {
user.getUsersFromSet(set, 0, 49, function(err, users) {
var uid = req.user ? parseInt(req.user.uid, 10) : 0;
user.getUsersFromSet(set, uid, 0, 49, function(err, users) {
if (err) {
return next(err);
}

@ -57,12 +57,13 @@ groupsController.details = function(req, res, next) {
};
groupsController.members = function(req, res, next) {
var uid = req.user ? parseInt(req.user.uid, 10) : 0;
async.waterfall([
function(next) {
groups.getGroupNameByGroupSlug(req.params.slug, next);
},
function(groupName, next) {
user.getUsersFromSet('group:' + groupName + ':members', 0, 49, next);
user.getUsersFromSet('group:' + groupName + ':members', uid, 0, 49, next);
},
], function(err, users) {
if (err) {

@ -14,7 +14,7 @@ usersController.getOnlineUsers = function(req, res, next) {
async.parallel({
users: function(next) {
user.getUsersFromSet('users:online', 0, 49, next);
user.getUsersFromSet('users:online', uid, 0, 49, next);
},
count: function(next) {
var now = Date.now();
@ -63,7 +63,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) {
usersController.getUsers = function(set, count, req, res, next) {
var uid = req.user ? req.user.uid : 0;
getUsersAndCount(set, count, function(err, data) {
getUsersAndCount(set, uid, count, function(err, data) {
if (err) {
return next(err);
}
@ -78,10 +78,10 @@ usersController.getUsers = function(set, count, req, res, next) {
});
};
function getUsersAndCount(set, count, callback) {
function getUsersAndCount(set, uid, count, callback) {
async.parallel({
users: function(next) {
user.getUsersFromSet(set, 0, count - 1, next);
user.getUsersFromSet(set, uid, 0, count - 1, next);
},
count: function(next) {
db.getObjectField('global', 'userCount', next);
@ -102,7 +102,7 @@ usersController.getUsersForSearch = function(req, res, next) {
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20,
uid = req.user ? req.user.uid : 0;
getUsersAndCount('users:joindate', resultsPerPage, function(err, data) {
getUsersAndCount('users:joindate', uid, resultsPerPage, function(err, data) {
if (err) {
return next(err);
}

@ -253,7 +253,7 @@ var async = require('async'),
}
if (!isFavouriting && !results.hasFavourited) {
return callback(new Error('[[error:alrady-unfavourited]]'));
return callback(new Error('[[error:already-unfavourited]]'));
}
async.waterfall([

@ -803,8 +803,12 @@ var async = require('async'),
groupData = groupData.filter(function(group) {
return parseInt(group.hidden, 10) !== 1 && !!group.userTitle;
}).map(function(group) {
group.createtimeISO = utils.toISOString(group.createtime);
return group;
});
var groupSets = groupData.map(function(group) {
group.labelColor = group.labelColor || '#000000';
group.createtimeISO = utils.toISOString(group.createtime);

@ -42,7 +42,7 @@ search.search = function(data, callback) {
if (searchIn === 'posts') {
searchInPosts(query, data, done);
} else if (searchIn === 'users') {
searchInUsers(query, done);
searchInUsers(query, data.uid, done);
} else if (searchIn === 'tags') {
searchInTags(query, done);
} else {
@ -291,8 +291,8 @@ function getChildrenCids(cids, uid, callback) {
});
}
function searchInUsers(query, callback) {
user.search({query: query}, function(err, results) {
function searchInUsers(query, uid, callback) {
user.search({query: query, uid: uid}, function(err, results) {
if (err) {
return callback(err);
}

@ -36,7 +36,7 @@ Categories.search = function(socket, data, callback) {
var username = data.username,
cid = data.cid;
user.search({query: username}, function(err, data) {
user.search({query: username, uid: socket.uid}, function(err, data) {
if (err) {
return callback(err);
}

@ -180,7 +180,7 @@ User.deleteUsers = function(socket, uids, callback) {
};
User.search = function(socket, data, callback) {
user.search({query: data.query, searchBy: data.searchBy, startsWith: false}, function(err, searchData) {
user.search({query: data.query, searchBy: data.searchBy, startsWith: false, uid: socket.uid}, function(err, searchData) {
if (err) {
return callback(err);
}

@ -67,7 +67,8 @@ SocketUser.search = function(socket, data, callback) {
page: data.page,
searchBy: data.searchBy,
sortBy: data.sortBy,
filterBy: data.filterBy
filterBy: data.filterBy,
uid: socket.uid
}, callback);
};
@ -393,7 +394,7 @@ SocketUser.loadMore = function(socket, data, callback) {
var start = parseInt(data.after, 10),
end = start + 19;
user.getUsersFromSet(data.set, start, end, function(err, userData) {
user.getUsersFromSet(data.set, socket.uid, start, end, function(err, userData) {
if (err) {
return callback(err);
}

@ -241,7 +241,9 @@ var async = require('async'),
topicData.locked = parseInt(topicData.locked, 10) === 1;
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
plugins.fireHook('filter:topic.get', topicData, callback);
plugins.fireHook('filter:topic.get', {topic: topicData, uid: uid}, function(err, data) {
callback(err, data ? data.topic : null);
});
});
});
};

@ -221,18 +221,18 @@ var async = require('async'),
}
};
User.getUsersFromSet = function(set, start, stop, callback) {
User.getUsersFromSet = function(set, uid, start, stop, callback) {
async.waterfall([
function(next) {
User.getUidsFromSet(set, start, stop, next);
},
function(uids, next) {
User.getUsers(uids, next);
User.getUsers(uids, uid, next);
}
], callback);
};
User.getUsers = function(uids, callback) {
User.getUsers = function(uids, uid, callback) {
var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation', 'email:confirmed'];
plugins.fireHook('filter:users.addFields', {fields: fields}, function(err, data) {
if (err) {
@ -266,11 +266,10 @@ var async = require('async'),
user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1;
});
plugins.fireHook('filter:userlist.get', {users: results.userData}, function(err, data) {
plugins.fireHook('filter:userlist.get', {users: results.userData, uid: uid}, function(err, data) {
if (err) {
return callback(err);
}
callback(null, data.users);
});
});

@ -59,7 +59,7 @@ module.exports = function(User) {
return callback(err);
}
User.getUsers(uids, callback);
User.getUsers(uids, uid, callback);
});
}

@ -14,13 +14,10 @@ module.exports = function(User) {
var searchBy = data.searchBy || ['username'];
var startsWith = data.hasOwnProperty('startsWith') ? data.startsWith : true;
var page = data.page || 1;
if (!query) {
return callback(null, {timing: 0, users: [], matchCount: 0, pages: []});
}
var uid = data.uid || 0;
if (searchBy.indexOf('ip') !== -1) {
return searchByIP(query, callback);
return searchByIP(query, uid, callback);
}
var startTime = process.hrtime();
@ -46,7 +43,7 @@ module.exports = function(User) {
matchCount = uids.length;
uids = uids.slice(start, end);
User.getUsers(uids, next);
User.getUsers(uids, uid, next);
},
function(userData, next) {
@ -194,14 +191,14 @@ module.exports = function(User) {
}
}
function searchByIP(ip, callback) {
function searchByIP(ip, uid, callback) {
var start = process.hrtime();
async.waterfall([
function(next) {
db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next);
},
function(uids, next) {
User.getUsers(uids, next);
User.getUsers(uids, uid, next);
},
function(users, next) {
var diff = process.hrtime(start);

Loading…
Cancel
Save