Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit b288edfb6b

@ -60,6 +60,7 @@
"online": "Online",
"away": "Away",
"donotdisturb": "Do not disturb",
"invisible": "Invisible"
"dnd": "Do not disturb",
"invisible": "Invisible",
"offline": "Offline"
}

@ -268,14 +268,13 @@ var socket,
});
socket.emit('user.getOnlineUsers', uids, function (err, users) {
jQuery('button .username-field').each(function (index, element) {
jQuery('.username-field').each(function (index, element) {
var el = jQuery(this),
uid = el.parents('li').attr('data-uid');
if (uid && jQuery.inArray(uid, users) !== -1) {
el.parent().addClass('btn-success').removeClass('btn-danger');
} else {
el.parent().addClass('btn-danger').removeClass('btn-success');
if (uid && users[uid]) {
el.siblings('i').attr('class', 'fa fa-circle status-' + users[uid].status)
}
});
});
@ -528,6 +527,14 @@ var socket,
$('.navbar-header button').click();
}
});
$('#user-control-list .user-status').off('click').on('click', function() {
socket.emit('user.setStatus', $(this).attr('data-status'), function(err) {
if(err) {
return app.alertError(err.message);
}
});
});
};
jQuery('document').ready(function () {

@ -84,13 +84,15 @@ define(['forum/accountheader'], function(header) {
Account.handleUserOnline = function(err, data) {
var onlineStatus = $('.account-online-status');
if (data.online) {
onlineStatus.find('span span').text('online');
onlineStatus.find('i').attr('class', 'fa fa-circle');
} else {
onlineStatus.find('span span').text('offline');
onlineStatus.find('i').attr('class', 'fa fa-circle-o');
if(parseInt(templates.get('theirid'), 10) !== parseInt(data.uid, 10)) {
return;
}
translator.get('global:' + data.status, function(translated) {
onlineStatus.find('span span').text(translated);
onlineStatus.find('i').attr('class', 'fa fa-circle status-' + data.status);
});
};
return Account;

@ -570,7 +570,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
'event:topic_deleted', 'event:topic_restored', 'event:topic:locked',
'event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned',
'event:topic_moved', 'event:post_edited', 'event:post_deleted', 'event:post_restored',
'posts.favourite'
'posts.favourite', 'user.isOnline'
]);
socket.on('get_users_in_room', function(data) {
@ -652,6 +652,11 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
});
}
}
app.populateOnlineUsers();
});
socket.on('user.isOnline', function(err, data) {
app.populateOnlineUsers();
});

@ -89,18 +89,9 @@ define(['taskbar', 'string'], function(taskbar, S) {
return $('#chat-modal-' + touid).length !== 0;
}
function checkStatus(chatModal, callback) {
function checkStatus(chatModal) {
socket.emit('user.isOnline', chatModal.touid, function(err, data) {
if(data.online !== chatModal.online) {
if(data.online) {
module.appendChatMessage(chatModal, chatModal.username + ' is currently online.\n', data.timestamp);
} else {
module.appendChatMessage(chatModal, chatModal.username + ' is currently offline.\n', data.timestamp);
}
chatModal.online = data.online;
}
if(callback)
callback(data.online);
$('#chat-user-status').attr('class', 'fa fa-circle status-' + data.status);
});
}

@ -13,7 +13,7 @@
<img src="{picture}" class="user-profile-picture img-thumbnail"/>
</div>
<div class="account-online-status">
<span><i class="fa fa-circle-o"></i> <span>[[user:offline]]</span></span>
<span><i class="fa fa-circle status-offline"></i> <span>[[user:offline]]</span></span>
</div>
<!-- IF banned -->
<div>

@ -4,7 +4,8 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4>[[modules:chat.chatting_with]]</h4>
<h4>[[modules:chat.chatting_with]] <i id="chat-user-status" class="fa fa-circle status-offline"></i></h4>
</div>
<div class="modal-body">
<ul id="chat-content" class="well well-sm"></ul>

@ -134,16 +134,16 @@
</li>
<li role="presentation" class="divider"></li>
<li>
<a href="#"><i class="fa fa-circle state-online"></i><span> [[global:online]]</span></a>
<a href="#" class="user-status" data-status="online"><i class="fa fa-circle status-online"></i><span> [[global:online]]</span></a>
</li>
<li>
<a href="#"><i class="fa fa-circle state-away"></i><span> [[global:away]]</span></a>
<a href="#" class="user-status" data-status="away"><i class="fa fa-circle status-away"></i><span> [[global:away]]</span></a>
</li>
<li>
<a href="#"><i class="fa fa-circle state-dnd"></i><span> [[global:donotdisturb]]</span></a>
<a href="#" class="user-status" data-status="dnd"><i class="fa fa-circle status-dnd"></i><span> [[global:dnd]]</span></a>
</li>
<li>
<a href="#"><i class="fa fa-circle state-invisible"></i><span> [[global:invisible]]</span></a>
<a href="#" class="user-status" data-status="offline"><i class="fa fa-circle status-offline"></i><span> [[global:invisible]]</span></a>
</li>
</ul>
</li>

@ -53,6 +53,7 @@
<div class="btn-group">
<button class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" type="button" title="[[topic:posted_by]] {posts.username}">
<i class="fa fa-circle status-offline"></i>
<span class="visible-xs visible-sm pull-left"><img class="" src="{posts.picture}" width=18 height=18 />&nbsp;</span>
<span class="username-field" href="{relative_path}/user/{posts.userslug}" itemprop="author">{posts.username}&nbsp;</span>
<span class="caret"></span>

@ -13,6 +13,7 @@ var SocketIO = require('socket.io'),
db = require('../database'),
user = require('../user'),
socketUser = require('./user'),
topics = require('../topics'),
logger = require('../logger'),
meta = require('../meta'),
@ -97,10 +98,8 @@ Sockets.init = function(server) {
});
}
socket.broadcast.emit('user.isOnline', null, {
online: isUserOnline(uid),
uid: uid,
timestamp: Date.now()
socketUser.isOnline(socket, uid, function(err, data) {
socket.broadcast.emit('user.isOnline', err, data);
});
});
});
@ -121,10 +120,8 @@ Sockets.init = function(server) {
}
}
socket.broadcast.emit('user.isOnline', null, {
online: isUserOnline(uid),
uid: uid,
timestamp: Date.now()
socketUser.isOnline(socket, uid, function(err, data) {
socket.broadcast.emit('user.isOnline', err, data);
});
emitOnlineUserCount();

@ -1,6 +1,6 @@
var user = require('../user'),
var async = require('async'),
user = require('../user'),
topics = require('../topics'),
SocketUser = {};
SocketUser.exists = function(socket, data, callback) {
@ -45,10 +45,30 @@ SocketUser.reset.commit = function(socket, data, callback) {
};
SocketUser.isOnline = function(socket, uid, callback) {
callback(null, {
online: module.parent.exports.isUserOnline(uid),
uid: uid,
timestamp: Date.now()
user.getUserField(uid, 'status', function(err, status) {
if(err) {
return callback(err);
}
if(!status) {
status = 'online';
}
var online = module.parent.exports.isUserOnline(uid);
if(!online) {
status = 'offline';
}
if(status === 'offline') {
online = false;
}
callback(null, {
online: online,
uid: uid,
timestamp: Date.now(),
status: status
});
});
};
@ -121,19 +141,24 @@ SocketUser.saveSettings = function(socket, data, callback) {
};
SocketUser.getOnlineUsers = function(socket, data, callback) {
var returnData = [];
if(data) {
for (var i = 0; i < data.length; ++i) {
var uid = data[i];
if (module.parent.exports.isUserOnline(uid)) {
returnData.push(uid);
} else {
returnData.push(0);
var returnData = {};
if(!data) {
return callback(new Error('invalid-data'));
}
function getUserStatus(uid, next) {
SocketUser.isOnline(socket, uid, function(err, data) {
if(err) {
return next(err);
}
}
returnData[uid] = data;
next();
});
}
callback(null, returnData);
async.each(data, getUserStatus, function(err) {
callback(err, returnData);
});
};
SocketUser.getOnlineAnonCount = function(socket, data, callback) {
@ -165,6 +190,15 @@ SocketUser.loadMore = function(socket, data, callback) {
}
};
SocketUser.setStatus = function(socket, status, callback) {
var server = require('./index');
user.setUserField(socket.uid, 'status', status, function(err) {
SocketUser.isOnline(socket, socket.uid, function(err, data) {
server.server.sockets.emit('user.isOnline', err, data);
});
});
};
/* Exports */
module.exports = SocketUser;

@ -105,6 +105,7 @@ var bcrypt = require('bcryptjs'),
'postcount': 0,
'lastposttime': 0,
'banned': 0,
'status': 'online',
'showemail': 0
};

Loading…
Cancel
Save