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'));
});
socket.emit('user.get_online_users', uids, function (users) {
socket.emit('user.getOnlineUsers', uids, function (err, users) {
jQuery('a.username-field').each(function () {
if (this.processed === true)
return;

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

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

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

@ -15,6 +15,15 @@ jQuery('document').ready(function() {
}, 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;
});

@ -73,17 +73,9 @@ define(['uploader'], function(uploader) {
socket.emit('admin.config.set', {
key: key,
value: value
}, function(data) {
if (data.status === 'ok') {
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({
}, function(err) {
if(err) {
return app.alert({
alert_id: 'config_status',
timeout: 2500,
title: 'Changes Not Saved',
@ -91,6 +83,15 @@ define(['uploader'], function(uploader) {
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', {
set: set,
after: $('#users-container').children().length
}, function(data) {
if (data.users.length) {
}, function(err, data) {
if (data && data.users.length) {
onUsersLoaded(data.users);
}
loadingMoreUsers = false;

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

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

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

@ -90,7 +90,7 @@ define(['taskbar', 'string'], function(taskbar, S) {
}
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) {
module.appendChatMessage(chatModal, chatModal.username + ' is currently online.\n', data.timestamp);

@ -15,6 +15,7 @@ var groups = require('../groups'),
async = require('async'),
winston = require('winston'),
index = require('./index'),
SocketAdmin = {};
@ -232,27 +233,23 @@ SocketAdmin.plugins.toggle = function(socket, plugin_id) {
SocketAdmin.config = {};
SocketAdmin.config.get = function(socket, data, callback) {
meta.configs.list(function(err, config) {
if (!err) {
callback(config);
}
});
meta.configs.list(callback);
};
SocketAdmin.config.set = function(socket, data, callback) {
meta.configs.set(data.key, data.value, function(err) {
if (!err) {
callback({
status: 'ok'
});
plugins.fireHook('action:config.set', {
key: data.key,
value: data.value
});
if(err) {
return callback(err);
}
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),
methodToCall = parts.reduce(function(prev, cur) {
if (prev !== null && prev[cur]) {
@ -151,17 +154,16 @@ Sockets.init = function() {
}
}, Namespaces);
if (methodToCall !== null) {
if(!methodToCall) {
return winston.warn('[socket.io] Unrecognized message: ' + payload.name);
}
if (Namespaces[namespace].before) {
Namespaces[namespace].before(socket, function() {
callMethod(methodToCall);
});
} else {
if (Namespaces[namespace].before) {
Namespaces[namespace].before(socket, function() {
callMethod(methodToCall);
}
});
} 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) {
user.email.exists(data.email, callback);
if(data && data.email) {
user.email.exists(data.email, callback);
}
};
// Password Reset
SocketUser.reset = {};
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) {
user.reset.validate(socket, data.code);
if(data && data.code) {
user.reset.validate(socket, data.code);
}
};
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) {
callback({
callback(null, {
online: module.parent.exports.isUserOnline(uid),
uid: uid,
timestamp: Date.now()
@ -41,88 +49,96 @@ SocketUser.isOnline = function(socket, uid, 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) {
user.updateProfile(socket.uid, data, callback);
if(data) {
user.updateProfile(socket.uid, data, callback);
}
};
SocketUser.changePicture = function(socket, data, callback) {
if(!data) {
return;
}
var type = data.type;
function updateHeader() {
user.getUserFields(socket.uid, ['picture'], function(err, fields) {
if (!err && fields) {
if(err) {
return callback(err);
}
if (fields) {
fields.uid = socket.uid;
socket.emit('meta.updateHeader', fields);
callback(true);
} else {
callback(false);
socket.emit('meta.updateHeader', null, fields);
}
callback(null);
});
}
if (type === 'gravatar') {
user.getUserField(socket.uid, 'gravatarpicture', function(err, gravatar) {
user.setUserField(socket.uid, 'picture', gravatar);
updateHeader();
});
type = 'gravatarpicture';
} else if (type === 'uploaded') {
user.getUserField(socket.uid, 'uploadedpicture', function(err, uploadedpicture) {
user.setUserField(socket.uid, 'picture', uploadedpicture);
updateHeader();
});
type = 'uploadedpicture';
} 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) {
if (socket.uid) {
if (socket.uid && data) {
user.follow(socket.uid, data.uid, callback);
}
};
SocketUser.unfollow = function(socket, data, callback) {
if (socket.uid) {
if (socket.uid && data) {
user.unfollow(socket.uid, data.uid, callback);
}
};
SocketUser.saveSettings = function(socket, data, callback) {
if (socket.uid) {
if (socket.uid && data) {
user.setUserFields(socket.uid, {
showemail: data.showemail
}, function(err, result) {
callback(err);
});
}, callback);
}
};
SocketUser.get_online_users = function(socket, data, callback) {
SocketUser.getOnlineUsers = function(socket, data, callback) {
var returnData = [];
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);
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);
}
}
}
callback(returnData);
callback(null, returnData);
};
SocketUser.getOnlineAnonCount = function(socket, data, callback) {
callback(module.parent.exports.getOnlineAnonCount());
callback(null, module.parent.exports.getOnlineAnonCount());
};
SocketUser.getUnreadCount = function(socket, data, callback) {
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) {
var start = data.after,
end = start + 19;
user.getUsers(data.set, start, end, function(err, data) {
if (err) {
winston.err(err);
} else {
callback({
if(data) {
var start = data.after,
end = start + 19;
user.getUsers(data.set, start, end, function(err, data) {
if(err) {
return callback(err);
}
callback(null, {
users: data
});
}
});
});
}
};
/* Exports */

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

Loading…
Cancel
Save