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

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

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

@ -268,14 +268,13 @@ var socket,
}); });
socket.emit('user.getOnlineUsers', uids, function (err, users) { 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), var el = jQuery(this),
uid = el.parents('li').attr('data-uid'); uid = el.parents('li').attr('data-uid');
if (uid && jQuery.inArray(uid, users) !== -1) { if (uid && users[uid]) {
el.parent().addClass('btn-success').removeClass('btn-danger'); el.siblings('i').attr('class', 'fa fa-circle status-' + users[uid].status)
} else {
el.parent().addClass('btn-danger').removeClass('btn-success');
} }
}); });
}); });
@ -528,6 +527,14 @@ var socket,
$('.navbar-header button').click(); $('.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 () { jQuery('document').ready(function () {

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

@ -570,7 +570,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
'event:topic_deleted', 'event:topic_restored', 'event:topic:locked', 'event:topic_deleted', 'event:topic_restored', 'event:topic:locked',
'event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned', 'event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned',
'event:topic_moved', 'event:post_edited', 'event:post_deleted', 'event:post_restored', '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) { 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(); app.populateOnlineUsers();
}); });

@ -89,18 +89,9 @@ define(['taskbar', 'string'], function(taskbar, S) {
return $('#chat-modal-' + touid).length !== 0; return $('#chat-modal-' + touid).length !== 0;
} }
function checkStatus(chatModal, callback) { function checkStatus(chatModal) {
socket.emit('user.isOnline', chatModal.touid, function(err, data) { socket.emit('user.isOnline', chatModal.touid, function(err, data) {
if(data.online !== chatModal.online) { $('#chat-user-status').attr('class', 'fa fa-circle status-' + data.status);
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);
}); });
} }

@ -13,7 +13,7 @@
<img src="{picture}" class="user-profile-picture img-thumbnail"/> <img src="{picture}" class="user-profile-picture img-thumbnail"/>
</div> </div>
<div class="account-online-status"> <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> </div>
<!-- IF banned --> <!-- IF banned -->
<div> <div>

@ -4,7 +4,8 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <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>
<div class="modal-body"> <div class="modal-body">
<ul id="chat-content" class="well well-sm"></ul> <ul id="chat-content" class="well well-sm"></ul>

@ -134,16 +134,16 @@
</li> </li>
<li role="presentation" class="divider"></li> <li role="presentation" class="divider"></li>
<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>
<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>
<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>
<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> </li>
</ul> </ul>
</li> </li>

@ -53,6 +53,7 @@
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" type="button" title="[[topic:posted_by]] {posts.username}"> <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="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="username-field" href="{relative_path}/user/{posts.userslug}" itemprop="author">{posts.username}&nbsp;</span>
<span class="caret"></span> <span class="caret"></span>

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

@ -1,6 +1,6 @@
var user = require('../user'), var async = require('async'),
user = require('../user'),
topics = require('../topics'), topics = require('../topics'),
SocketUser = {}; SocketUser = {};
SocketUser.exists = function(socket, data, callback) { SocketUser.exists = function(socket, data, callback) {
@ -45,10 +45,30 @@ SocketUser.reset.commit = function(socket, data, callback) {
}; };
SocketUser.isOnline = function(socket, uid, callback) { SocketUser.isOnline = function(socket, uid, callback) {
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, { callback(null, {
online: module.parent.exports.isUserOnline(uid), online: online,
uid: uid, uid: uid,
timestamp: Date.now() timestamp: Date.now(),
status: status
});
}); });
}; };
@ -121,19 +141,24 @@ SocketUser.saveSettings = function(socket, data, callback) {
}; };
SocketUser.getOnlineUsers = function(socket, data, callback) { SocketUser.getOnlineUsers = function(socket, data, callback) {
var returnData = []; var returnData = {};
if(data) { if(!data) {
for (var i = 0; i < data.length; ++i) { return callback(new Error('invalid-data'));
var uid = data[i];
if (module.parent.exports.isUserOnline(uid)) {
returnData.push(uid);
} else {
returnData.push(0);
} }
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) { 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 */ /* Exports */
module.exports = SocketUser; module.exports = SocketUser;

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

Loading…
Cancel
Save