v1.18.x
Baris Usakli 11 years ago
parent 043aafd7b7
commit 776b51fef7

@ -275,7 +275,7 @@ var socket,
if (active) {
jQuery('#main-nav li a').each(function() {
var href = this.getAttribute('href');
if (active == "sort-posts" || active == "sort-reputation" || active == "search" || active== "latest")
if (active == "sort-posts" || active == "sort-reputation" || active == "search" || active == "latest" || active == "online")
active = 'users';
if (href && href.match(active)) {
jQuery(this.parentNode).addClass('active');

@ -74,7 +74,10 @@
});
socket.on('api:user.isOnline', function(data) {
$('#users-container').empty();
startLoading('users:online', 0);
});
function onUsersLoaded(users) {
var html = templates.prepare(templates['users'].blocks['users']).parse({
@ -91,24 +94,32 @@
set = 'users:postcount';
} else if (active === 'sort-reputation') {
set = 'users:reputation';
} else if (active === 'online') {
set = 'users:online';
}
if (set) {
loadingMoreUsers = true;
socket.emit('api:users.loadMore', {
set: set,
after: $('#users-container').children().length
}, function(data) {
if (data.users.length) {
onUsersLoaded(data.users);
} else {
$('#load-more-users-btn').addClass('disabled');
}
loadingMoreUsers = false;
});
startLoading(set, $('#users-container').children().length);
}
}
function startLoading(set, after) {
socket.emit('api:users.loadMore', {
set: set,
after: after
}, function(data) {
if (data.users.length) {
onUsersLoaded(data.users);
$('#load-more-users-btn').removeClass('disabled');
} else {
$('#load-more-users-btn').addClass('disabled');
}
loadingMoreUsers = false;
});
}
$('#load-more-users-btn').on('click', loadMoreUsers);
$(window).off('scroll').on('scroll', function() {

@ -3,6 +3,7 @@
<li class=''><a href='/users/latest'>Latest Users</a></li>
<li class=''><a href='/users/sort-posts'>Top Posters</a></li>
<li class=''><a href='/users/sort-reputation'>Most Reputation</a></li>
<li class=''><a href='/users/online'>Online</a></li>
<li class=''><a href='/users/search'>Search</a></li>
</ul>

@ -137,7 +137,7 @@ var fs = require('fs'),
hookList = this.loadedHooks[hook];
if (hookList && Array.isArray(hookList)) {
if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\'');
//if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\'');
var hookType = hook.split(':')[0];
switch (hookType) {
case 'filter':

@ -25,7 +25,6 @@ var user = require('./../user.js'),
});
}
});
});
app.get('/users', function(req, res) {
@ -64,6 +63,15 @@ var user = require('./../user.js'),
});
});
app.get('/users/online', function(req, res) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route("users/online", "users") + templates['footer']);
});
});
app.get('/users/search', function(req, res) {
app.build_header({
req: req,
@ -136,7 +144,7 @@ var user = require('./../user.js'),
app.post('/user/uploadpicture', function(req, res) {
if (!req.user)
return res.redirect('/403');
var uploadSize = meta.config.maximumProfileImageSize || 256;
if (req.files.userPhoto.size > uploadSize * 1024) {
@ -342,7 +350,7 @@ var user = require('./../user.js'),
return;
}
user.getUserFields(uid, ['username', 'userslug', 'showemail'], function(err, userData) {
if (err)
return next(err);
@ -436,6 +444,7 @@ var user = require('./../user.js'),
app.get('/api/users/sort-posts', getUsersSortedByPosts);
app.get('/api/users/sort-reputation', getUsersSortedByReputation);
app.get('/api/users/latest', getUsersSortedByJoinDate);
app.get('/api/users/online', getOnlineUsers);
app.get('/api/users/search', getUsersForSearch);
@ -469,6 +478,16 @@ var user = require('./../user.js'),
});
}
function getOnlineUsers(req, res) {
user.getUsers('users:online', 0, 49, function(err, data) {
res.json({
search_display: 'none',
loadmore_display: 'block',
users: data
});
});
}
function getUsersForSearch(req, res) {
res.json({
search_display: 'block',

@ -23,6 +23,7 @@ var SocketIO = require('socket.io').listen(global.server, {
client: RDB,
ttl: 60 * 60 * 24 * 14
}),
nconf = require('nconf'),
socketCookieParser = express.cookieParser(nconf.get('secret')),
admin = {
'categories': require('./admin/categories.js'),
@ -53,14 +54,17 @@ var SocketIO = require('socket.io').listen(global.server, {
userSockets[uid].push(socket);
if (uid) {
socket.join('uid_' + uid);
io.sockets. in ('global').emit('api:user.isOnline', isUserOnline(uid));
user.getUserField(uid, 'username', function(err, username) {
socket.emit('event:connect', {
status: 1,
username: username,
uid: uid
RDB.zadd('users:online', Date.now(), uid, function(err, data) {
socket.join('uid_' + uid);
io.sockets. in ('global').emit('api:user.isOnline', isUserOnline(uid));
user.getUserField(uid, 'username', function(err, username) {
socket.emit('event:connect', {
status: 1,
username: username,
uid: uid
});
});
});
}
@ -80,7 +84,9 @@ var SocketIO = require('socket.io').listen(global.server, {
delete users[sessionID];
delete userSockets[uid];
if (uid) {
io.sockets. in ('global').emit('api:user.isOnline', isUserOnline(uid));
RDB.zrem('users:online', uid, function(err, data) {
io.sockets. in ('global').emit('api:user.isOnline', isUserOnline(uid));
});
}
}
@ -100,7 +106,7 @@ var SocketIO = require('socket.io').listen(global.server, {
socket.on('api:get_all_rooms', function(data) {
socket.emit('api:get_all_rooms', io.sockets.manager.rooms);
})
});
function updateRoomBrowsingText(roomName) {

Loading…
Cancel
Save