Merge branch 'socketAL-fix' of github.com:designcreateplay/NodeBB into socketAL-fix

v1.18.x
Julian Lam 11 years ago
commit 8041bee9fd

@ -253,7 +253,7 @@ var socket,
uids.push(this.getAttribute('data-uid')); uids.push(this.getAttribute('data-uid'));
}); });
socket.emit('user.get_online_users', uids, function (users) { socket.emit('user.getOnlineUsers', uids, function (err, users) {
jQuery('a.username-field').each(function () { jQuery('a.username-field').each(function () {
if (this.processed === true) if (this.processed === true)
return; return;

@ -37,14 +37,14 @@ define(['forum/accountheader'], function(header) {
followBtn.on('click', function() { followBtn.on('click', function() {
socket.emit('user.follow', { socket.emit('user.follow', {
uid: theirid uid: theirid
}, function(success) { }, function(err) {
if (success) { if(err) {
followBtn.addClass('hide'); return app.alertError('There was an error following' + username + '!');
unfollowBtn.removeClass('hide');
app.alertSuccess('You are now following ' + username + '!');
} else {
app.alertError('There was an error following' + username + '!');
} }
followBtn.addClass('hide');
unfollowBtn.removeClass('hide');
app.alertSuccess('You are now following ' + username + '!');
}); });
return false; return false;
}); });
@ -52,14 +52,14 @@ define(['forum/accountheader'], function(header) {
unfollowBtn.on('click', function() { unfollowBtn.on('click', function() {
socket.emit('user.unfollow', { socket.emit('user.unfollow', {
uid: theirid uid: theirid
}, function(success) { }, function(err) {
if (success) { if(err) {
followBtn.removeClass('hide'); return app.alertError('There was an error unfollowing ' + username + '!');
unfollowBtn.addClass('hide');
app.alertSuccess('You are no longer following ' + username + '!');
} else {
app.alertError('There was an error unfollowing ' + username + '!');
} }
followBtn.removeClass('hide');
unfollowBtn.addClass('hide');
app.alertSuccess('You are no longer following ' + username + '!');
}); });
return false; return false;
}); });
@ -85,7 +85,7 @@ define(['forum/accountheader'], function(header) {
}); });
}; };
Account.handleUserOnline = function(data) { Account.handleUserOnline = function(err, data) {
var onlineStatus = $('.account-online-status'); var onlineStatus = $('.account-online-status');
if (data.online) { if (data.online) {

@ -36,7 +36,7 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
gravatarPicture = data.gravatarpicture; gravatarPicture = data.gravatarpicture;
} }
} else { } else {
app.alertError('There was an error updating your profile! ' + err.error); app.alertError('There was an error updating your profile! ' + err.message);
} }
}); });
return false; return false;
@ -186,7 +186,7 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
passwordvalid = false; passwordvalid = false;
if (err) { if (err) {
app.alertError(err.error); app.alertError(err.message);
return; return;
} }
@ -206,9 +206,9 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
type: type type: type
}; };
socket.emit('user.changePicture', userData, function(success) { socket.emit('user.changePicture', userData, function(err) {
if (!success) { if(err) {
app.alertError('There was an error changing picture!'); app.alertError(err.message);
} }
}); });
} }

@ -11,11 +11,10 @@ define(['forum/accountheader'], function(header) {
}; };
socket.emit('user.saveSettings', settings, function(err) { socket.emit('user.saveSettings', settings, function(err) {
if (!err) { if (err) {
app.alertSuccess('Settings saved!'); return app.alertError('There was an error saving settings!');
} else {
app.alertError('There was an error saving settings!');
} }
app.alertSuccess('Settings saved!');
}); });
return false; return false;
}); });

@ -15,6 +15,15 @@ jQuery('document').ready(function() {
}, false); }, false);
}); });
socket.emit('admin.config.get', function(config) { socket.emit('admin.config.get', function(err, config) {
if(err) {
return app.alert({
alert_id: 'config_status',
timeout: 2500,
title: 'Error',
message: 'NodeBB encountered a problem getting config',
type: 'danger'
});
}
app.config = config; app.config = config;
}); });

@ -73,17 +73,9 @@ define(['uploader'], function(uploader) {
socket.emit('admin.config.set', { socket.emit('admin.config.set', {
key: key, key: key,
value: value value: value
}, function(data) { }, function(err) {
if (data.status === 'ok') { if(err) {
app.alert({ return app.alert({
alert_id: 'config_status',
timeout: 2500,
title: 'Changes Saved',
message: 'Your changes to the NodeBB configuration have been saved.',
type: 'success'
});
} else {
app.alert({
alert_id: 'config_status', alert_id: 'config_status',
timeout: 2500, timeout: 2500,
title: 'Changes Not Saved', title: 'Changes Not Saved',
@ -91,6 +83,15 @@ define(['uploader'], function(uploader) {
type: 'danger' type: 'danger'
}); });
} }
app.alert({
alert_id: 'config_status',
timeout: 2500,
title: 'Changes Saved',
message: 'Your changes to the NodeBB configuration have been saved.',
type: 'success'
});
}); });
} }
}); });

@ -245,8 +245,8 @@ define(function() {
socket.emit('user.loadMore', { socket.emit('user.loadMore', {
set: set, set: set,
after: $('#users-container').children().length after: $('#users-container').children().length
}, function(data) { }, function(err, data) {
if (data.users.length) { if (data && data.users.length) {
onUsersLoaded(data.users); onUsersLoaded(data.users);
} }
loadingMoreUsers = false; loadingMoreUsers = false;

@ -8,7 +8,7 @@ define(['notifications', 'chat'], function(Notifications, Chat) {
Chat.prepareDOM(); Chat.prepareDOM();
translator.prepareDOM(); translator.prepareDOM();
function updateUnreadCount(count) { function updateUnreadCount(err, count) {
$('#unread-count').toggleClass('unread-count', count > 0); $('#unread-count').toggleClass('unread-count', count > 0);
$('#unread-count').attr('data-content', count > 20 ? '20+' : count); $('#unread-count').attr('data-content', count > 20 ? '20+' : count);
} }

@ -44,7 +44,11 @@ define(function() {
} else { } else {
socket.emit('user.emailExists', { socket.emit('user.emailExists', {
email: emailEl.val() email: emailEl.val()
}, function(exists) { }, function(err, exists) {
if(err) {
return app.alertError(err.message);
}
if (exists) { if (exists) {
showError(email_notify, 'Email address already taken!'); showError(email_notify, 'Email address already taken!');
} else { } else {

@ -80,10 +80,10 @@ define(function() {
}, 250); }, 250);
}); });
socket.on('user.isOnline', function(data) { socket.on('user.isOnline', function(err, data) {
if(getActiveSection() == 'online' && !loadingMoreUsers) { if(getActiveSection() == 'online' && !loadingMoreUsers) {
startLoading('users:online', 0, true); startLoading('users:online', 0, true);
socket.emit('user.getOnlineAnonCount', {} , function(anonCount) { socket.emit('user.getOnlineAnonCount', {} , function(err, anonCount) {
if(parseInt(anonCount, 10) > 0) { if(parseInt(anonCount, 10) > 0) {
$('#users-container .anon-user').removeClass('hide'); $('#users-container .anon-user').removeClass('hide');
$('#online_anon_count').html(anonCount); $('#online_anon_count').html(anonCount);
@ -126,8 +126,8 @@ define(function() {
socket.emit('user.loadMore', { socket.emit('user.loadMore', {
set: set, set: set,
after: after after: after
}, function(data) { }, function(err, data) {
if (data.users.length) { if (data && data.users.length) {
onUsersLoaded(data.users, emptyContainer); onUsersLoaded(data.users, emptyContainer);
$('#load-more-users-btn').removeClass('disabled'); $('#load-more-users-btn').removeClass('disabled');
} else { } else {

@ -90,7 +90,7 @@ define(['taskbar', 'string'], function(taskbar, S) {
} }
function checkStatus(chatModal, callback) { function checkStatus(chatModal, callback) {
socket.emit('user.isOnline', chatModal.touid, function(data) { socket.emit('user.isOnline', chatModal.touid, function(err, data) {
if(data.online !== chatModal.online) { if(data.online !== chatModal.online) {
if(data.online) { if(data.online) {
module.appendChatMessage(chatModal, chatModal.username + ' is currently online.\n', data.timestamp); module.appendChatMessage(chatModal, chatModal.username + ' is currently online.\n', data.timestamp);

@ -15,6 +15,7 @@ var groups = require('../groups'),
async = require('async'), async = require('async'),
winston = require('winston'), winston = require('winston'),
index = require('./index'),
SocketAdmin = {}; SocketAdmin = {};
@ -232,27 +233,23 @@ SocketAdmin.plugins.toggle = function(socket, plugin_id) {
SocketAdmin.config = {}; SocketAdmin.config = {};
SocketAdmin.config.get = function(socket, data, callback) { SocketAdmin.config.get = function(socket, data, callback) {
meta.configs.list(function(err, config) { meta.configs.list(callback);
if (!err) {
callback(config);
}
});
}; };
SocketAdmin.config.set = function(socket, data, callback) { SocketAdmin.config.set = function(socket, data, callback) {
meta.configs.set(data.key, data.value, function(err) { meta.configs.set(data.key, data.value, function(err) {
if (!err) { if(err) {
callback({ return callback(err);
status: 'ok'
});
plugins.fireHook('action:config.set', {
key: data.key,
value: data.value
});
} }
logger.monitorConfig({io: socket.server}, data); callback(null);
plugins.fireHook('action:config.set', {
key: data.key,
value: data.value
});
logger.monitorConfig({io: index.server}, data);
}); });
}; };

@ -140,8 +140,11 @@ Sockets.init = function() {
}); });
} }
if(!payload.name) {
return winston.warn('[socket.io] Empty method name');
}
var parts = payload.name.split('.'), var parts = payload.name.toString().split('.'),
namespace = parts.slice(0, 1), namespace = parts.slice(0, 1),
methodToCall = parts.reduce(function(prev, cur) { methodToCall = parts.reduce(function(prev, cur) {
if (prev !== null && prev[cur]) { if (prev !== null && prev[cur]) {
@ -151,17 +154,16 @@ Sockets.init = function() {
} }
}, Namespaces); }, Namespaces);
if (methodToCall !== null) { if(!methodToCall) {
return winston.warn('[socket.io] Unrecognized message: ' + payload.name);
}
if (Namespaces[namespace].before) { if (Namespaces[namespace].before) {
Namespaces[namespace].before(socket, function() { Namespaces[namespace].before(socket, function() {
callMethod(methodToCall);
});
} else {
callMethod(methodToCall); callMethod(methodToCall);
} });
} else { } else {
winston.warn('[socket.io] Unrecognized message: ' + payload.name); callMethod(methodToCall);
} }
}); });
}); });

@ -14,26 +14,34 @@ SocketUser.count = function(socket, data, callback) {
}; };
SocketUser.emailExists = function(socket, data, callback) { SocketUser.emailExists = function(socket, data, callback) {
user.email.exists(data.email, callback); if(data && data.email) {
user.email.exists(data.email, callback);
}
}; };
// Password Reset // Password Reset
SocketUser.reset = {}; SocketUser.reset = {};
SocketUser.reset.send = function(socket, data, callback) { SocketUser.reset.send = function(socket, data, callback) {
user.reset.send(socket, data.email); if(data && data.email) {
user.reset.send(socket, data.email);
}
}; };
SocketUser.reset.valid = function(socket, data, callback) { SocketUser.reset.valid = function(socket, data, callback) {
user.reset.validate(socket, data.code); if(data && data.code) {
user.reset.validate(socket, data.code);
}
}; };
SocketUser.reset.commit = function(socket, data, callback) { SocketUser.reset.commit = function(socket, data, callback) {
user.reset.commit(socket, data.code, data.password); if(data && data.code && data.password) {
user.reset.commit(socket, data.code, data.password);
}
}; };
SocketUser.isOnline = function(socket, uid, callback) { SocketUser.isOnline = function(socket, uid, callback) {
callback({ callback(null, {
online: module.parent.exports.isUserOnline(uid), online: module.parent.exports.isUserOnline(uid),
uid: uid, uid: uid,
timestamp: Date.now() timestamp: Date.now()
@ -41,88 +49,96 @@ SocketUser.isOnline = function(socket, uid, callback) {
}; };
SocketUser.changePassword = function(socket, data, callback) { SocketUser.changePassword = function(socket, data, callback) {
user.changePassword(socket.uid, data, callback); if(data) {
user.changePassword(socket.uid, data, callback);
}
}; };
SocketUser.updateProfile = function(socket, data, callback) { SocketUser.updateProfile = function(socket, data, callback) {
user.updateProfile(socket.uid, data, callback); if(data) {
user.updateProfile(socket.uid, data, callback);
}
}; };
SocketUser.changePicture = function(socket, data, callback) { SocketUser.changePicture = function(socket, data, callback) {
if(!data) {
return;
}
var type = data.type; var type = data.type;
function updateHeader() { function updateHeader() {
user.getUserFields(socket.uid, ['picture'], function(err, fields) { user.getUserFields(socket.uid, ['picture'], function(err, fields) {
if (!err && fields) { if(err) {
return callback(err);
}
if (fields) {
fields.uid = socket.uid; fields.uid = socket.uid;
socket.emit('meta.updateHeader', fields); socket.emit('meta.updateHeader', null, fields);
callback(true);
} else {
callback(false);
} }
callback(null);
}); });
} }
if (type === 'gravatar') { if (type === 'gravatar') {
user.getUserField(socket.uid, 'gravatarpicture', function(err, gravatar) { type = 'gravatarpicture';
user.setUserField(socket.uid, 'picture', gravatar);
updateHeader();
});
} else if (type === 'uploaded') { } else if (type === 'uploaded') {
user.getUserField(socket.uid, 'uploadedpicture', function(err, uploadedpicture) { type = 'uploadedpicture';
user.setUserField(socket.uid, 'picture', uploadedpicture);
updateHeader();
});
} else { } else {
callback(false); return callback(new Error('invalid-image-type'));
} }
user.getUserField(socket.uid, type, function(err, picture) {
user.setUserField(socket.uid, 'picture', picture);
updateHeader();
});
}; };
SocketUser.follow = function(socket, data, callback) { SocketUser.follow = function(socket, data, callback) {
if (socket.uid) { if (socket.uid && data) {
user.follow(socket.uid, data.uid, callback); user.follow(socket.uid, data.uid, callback);
} }
}; };
SocketUser.unfollow = function(socket, data, callback) { SocketUser.unfollow = function(socket, data, callback) {
if (socket.uid) { if (socket.uid && data) {
user.unfollow(socket.uid, data.uid, callback); user.unfollow(socket.uid, data.uid, callback);
} }
}; };
SocketUser.saveSettings = function(socket, data, callback) { SocketUser.saveSettings = function(socket, data, callback) {
if (socket.uid) { if (socket.uid && data) {
user.setUserFields(socket.uid, { user.setUserFields(socket.uid, {
showemail: data.showemail showemail: data.showemail
}, function(err, result) { }, callback);
callback(err);
});
} }
}; };
SocketUser.get_online_users = function(socket, data, callback) { SocketUser.getOnlineUsers = function(socket, data, callback) {
var returnData = []; var returnData = [];
if(data) {
for (var i = 0; i < data.length; ++i) { for (var i = 0; i < data.length; ++i) {
var uid = data[i]; var uid = data[i];
if (module.parent.exports.isUserOnline(uid)) { if (module.parent.exports.isUserOnline(uid)) {
returnData.push(uid); returnData.push(uid);
} else { } else {
returnData.push(0); returnData.push(0);
}
} }
} }
callback(returnData); callback(null, returnData);
}; };
SocketUser.getOnlineAnonCount = function(socket, data, callback) { SocketUser.getOnlineAnonCount = function(socket, data, callback) {
callback(module.parent.exports.getOnlineAnonCount()); callback(null, module.parent.exports.getOnlineAnonCount());
}; };
SocketUser.getUnreadCount = function(socket, data, callback) { SocketUser.getUnreadCount = function(socket, data, callback) {
topics.getUnreadTids(socket.uid, 0, 19, function(err, tids) { topics.getUnreadTids(socket.uid, 0, 19, function(err, tids) {
callback(tids.length); callback(err, tids?tids.length:0);
}); });
}; };
@ -131,18 +147,20 @@ SocketUser.getActiveUsers = function(socket, data, callback) {
}; };
SocketUser.loadMore = function(socket, data, callback) { SocketUser.loadMore = function(socket, data, callback) {
var start = data.after, if(data) {
end = start + 19; var start = data.after,
end = start + 19;
user.getUsers(data.set, start, end, function(err, data) {
if (err) { user.getUsers(data.set, start, end, function(err, data) {
winston.err(err); if(err) {
} else { return callback(err);
callback({ }
callback(null, {
users: data users: data
}); });
} });
}); }
}; };
/* Exports */ /* Exports */

@ -347,13 +347,11 @@ var bcrypt = require('bcrypt'),
User.changePassword = function(uid, data, callback) { User.changePassword = function(uid, data, callback) {
if (!utils.isPasswordValid(data.newPassword)) { if (!utils.isPasswordValid(data.newPassword)) {
return callback({ return callback(new Error('Invalid password!'));
error: 'Invalid password!'
});
} }
User.getUserField(uid, 'password', function(err, user_password) { User.getUserField(uid, 'password', function(err, currentPassword) {
bcrypt.compare(data.currentPassword, user_password, function(err, res) { bcrypt.compare(data.currentPassword, currentPassword, function(err, res) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
@ -365,9 +363,7 @@ var bcrypt = require('bcrypt'),
callback(null); callback(null);
}); });
} else { } else {
callback({ callback(new Error('Your current password is not correct!'));
error: 'Your current password is not correct!'
});
} }
}); });
}); });
@ -541,31 +537,21 @@ var bcrypt = require('bcrypt'),
User.follow = function(uid, followid, callback) { User.follow = function(uid, followid, callback) {
db.setAdd('following:' + uid, followid, function(err, data) { db.setAdd('following:' + uid, followid, function(err, data) {
if (!err) { if(err) {
db.setAdd('followers:' + followid, uid, function(err, data) { return callback(err);
if (!err) {
callback(true);
} else {
console.log(err);
callback(false);
}
});
} else {
console.log(err);
callback(false);
} }
db.setAdd('followers:' + followid, uid, callback);
}); });
}; };
User.unfollow = function(uid, unfollowid, callback) { User.unfollow = function(uid, unfollowid, callback) {
db.setRemove('following:' + uid, unfollowid, function(err, data) { db.setRemove('following:' + uid, unfollowid, function(err, data) {
if (!err) { if(err) {
db.setRemove('followers:' + unfollowid, uid, function(err, data) { return callback(err);
callback(data);
});
} else {
console.log(err);
} }
db.setRemove('followers:' + unfollowid, uid, callback);
}); });
}; };
@ -933,7 +919,7 @@ var bcrypt = require('bcrypt'),
}, },
exists: function(email, callback) { exists: function(email, callback) {
User.getUidByEmail(email, function(err, exists) { User.getUidByEmail(email, function(err, exists) {
callback(!!exists); callback(err, !!exists);
}); });
}, },
confirm: function(code, callback) { confirm: function(code, callback) {

Loading…
Cancel
Save