Added block and unblock button to profile dropdown menu, #6560

v1.18.x
Julian Lam 7 years ago
parent a34584e8f5
commit 7a53fa9469

@ -33,6 +33,8 @@
"following": "Following",
"blocks": "Blocks",
"block_toggle": "Toggle Block",
"block_user": "Block User",
"unblock_user": "Unblock User",
"aboutme": "About me",
"signature": "Signature",
"birthday": "Birthday",

@ -53,6 +53,7 @@ define('forum/account/header', [
components.get('account/unban').on('click', unbanAccount);
components.get('account/delete').on('click', deleteAccount);
components.get('account/flag').on('click', flagAccount);
components.get('account/block').on('click', toggleBlockAccount);
};
function hidePrivateLinks() {
@ -191,6 +192,25 @@ define('forum/account/header', [
});
}
function toggleBlockAccount() {
var targetEl = this;
socket.emit('user.toggleBlock', {
blockeeUid: ajaxify.data.uid,
blockerUid: app.user.uid,
}, function (err, blocked) {
if (err) {
return app.alertError(err.message);
}
translator.translate('[[user:' + (blocked ? 'unblock' : 'block') + '_user]]', function (label) {
$(targetEl).text(label);
});
});
// Keep dropdown open
return false;
}
function removeCover() {
translator.translate('[[user:remove_cover_picture_confirm]]', function (translated) {
bootbox.confirm(translated, function (confirm) {

@ -91,6 +91,9 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
canBanUser: function (next) {
privileges.users.canBanUser(callerUID, uid, next);
},
isBlocked: function (next) {
user.blocks.is(uid, callerUID, next);
},
}, next);
},
function (results, next) {
@ -129,6 +132,11 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
userData.moderationNote = undefined;
}
userData.isBlocked = results.isBlocked;
if (isAdmin || isSelf) {
userData.blocksCount = parseInt(userData.blocksCount, 10) || 0;
}
userData.yourid = callerUID;
userData.theirid = userData.uid;
userData.isTargetAdmin = results.isTargetAdmin;
@ -165,7 +173,6 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
userData.followingCount = parseInt(userData.followingCount, 10) || 0;
userData.followerCount = parseInt(userData.followerCount, 10) || 0;
userData.blocksCount = parseInt(userData.blocksCount, 10) || 0;
userData.email = validator.escape(String(userData.email || ''));
userData.fullname = validator.escape(String(userData.fullname || ''));

@ -223,16 +223,4 @@ module.exports = function (middleware) {
return next();
}
};
middleware.handleBlocking = function (req, res, next) {
user.blocks.is(res.locals.uid, req.uid, function (err, blocked) {
if (err) {
return next(err);
} else if (blocked) {
res.status(404).render('404', { title: '[[global:404.title]]' });
} else {
return next();
}
});
};
};

@ -4,8 +4,8 @@ var helpers = require('./helpers');
var setupPageRoute = helpers.setupPageRoute;
module.exports = function (app, middleware, controllers) {
var middlewares = [middleware.checkGlobalPrivacySettings, middleware.exposeUid, middleware.handleBlocking];
var accountMiddlewares = [middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, middleware.exposeUid, middleware.handleBlocking];
var middlewares = [middleware.checkGlobalPrivacySettings, middleware.exposeUid];
var accountMiddlewares = [middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, middleware.exposeUid];
setupPageRoute(app, '/me/*', middleware, [], middleware.redirectMeToUserslug);
setupPageRoute(app, '/uid/:uid*', middleware, [], middleware.redirectUidToUserslug);

@ -201,6 +201,8 @@ module.exports = function (SocketUser) {
};
SocketUser.toggleBlock = function (socket, data, callback) {
let current;
async.waterfall([
function (next) {
user.blocks.can(socket.uid, data.blockerUid, data.blockeeUid, next);
@ -212,8 +214,11 @@ module.exports = function (SocketUser) {
user.blocks.is(data.blockeeUid, data.blockerUid, next);
},
function (is, next) {
current = is;
user.blocks[is ? 'remove' : 'add'](data.blockeeUid, data.blockerUid, next);
},
], callback);
], function (err) {
callback(err, !current);
});
};
};

Loading…
Cancel
Save