diff --git a/public/src/app.js b/public/src/app.js index 0460e440d7..f054575011 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -66,6 +66,8 @@ app.cacheBuster = null; }, 1000); }); + socket.on('event:logout', app.logout); + socket.on('event:alert', function(data) { app.alert(data); }); diff --git a/public/src/client/account/edit.js b/public/src/client/account/edit.js index e44d9f3f81..42dd151e6f 100644 --- a/public/src/client/account/edit.js +++ b/public/src/client/account/edit.js @@ -157,8 +157,8 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], return false; } else { socket.emit('user.deleteAccount', {}, function(err) { - if (!err) { - app.logout(); + if (err) { + app.alertError(err.message); } }); } diff --git a/src/groups.js b/src/groups.js index 90053643d3..a66555104e 100644 --- a/src/groups.js +++ b/src/groups.js @@ -115,6 +115,10 @@ var async = require('async'), return next(err); } + uids = uids.filter(function(uid) { + return uid && parseInt(uid, 10); + }); + if (options.truncateUserList) { var userListCount = parseInt(options.userListCount, 10) || 4; if (uids.length > userListCount) { diff --git a/src/messaging.js b/src/messaging.js index d80cf4a78c..cd3e1f96e2 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -250,6 +250,12 @@ var db = require('./database'), return callback(err); } + results.users.forEach(function(user, index) { + if (user && !parseInt(user.uid, 10)) { + Messaging.markRead(uid, uids[index]); + } + }); + results.users = results.users.filter(function(user) { return user && parseInt(user.uid, 10); }); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 02a7aee65e..0df36121e8 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -24,20 +24,27 @@ SocketUser.exists = function(socket, data, callback) { }; SocketUser.deleteAccount = function(socket, data, callback) { - if (socket.uid) { - user.isAdministrator(socket.uid, function(err, isAdmin) { - if (err || isAdmin) { - return callback(err || new Error('[[error:cant-delete-admin]]')); - } + if (!socket.uid) { + return; + } + user.isAdministrator(socket.uid, function(err, isAdmin) { + if (err || isAdmin) { + return callback(err || new Error('[[error:cant-delete-admin]]')); + } - socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: 'offline'}); - user.deleteAccount(socket.uid, callback); + socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: 'offline'}); + user.deleteAccount(socket.uid, function(err) { + if (err) { + return callback(err); + } + websockets.in('uid_' + socket.uid).emit('event:logout'); + callback(); }); - } + }); }; SocketUser.emailExists = function(socket, data, callback) { - if(data && data.email) { + if (data && data.email) { user.email.exists(data.email, callback); } };