mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
additional UCP integration for #6463
This commit is contained in:
@@ -96,6 +96,7 @@
|
|||||||
"has_no_upvoted_posts": "This user hasn't upvoted any posts yet.",
|
"has_no_upvoted_posts": "This user hasn't upvoted any posts yet.",
|
||||||
"has_no_downvoted_posts": "This user hasn't downvoted any posts yet.",
|
"has_no_downvoted_posts": "This user hasn't downvoted any posts yet.",
|
||||||
"has_no_voted_posts": "This user has no voted posts",
|
"has_no_voted_posts": "This user has no voted posts",
|
||||||
|
"has_no_blocks": "You have blocked no users.",
|
||||||
|
|
||||||
"email_hidden": "Email Hidden",
|
"email_hidden": "Email Hidden",
|
||||||
"hidden": "hidden",
|
"hidden": "hidden",
|
||||||
|
|||||||
13
public/src/client/account/blocks.js
Normal file
13
public/src/client/account/blocks.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
define('forum/account/blocks', ['forum/account/header'], function (header) {
|
||||||
|
var Blocks = {};
|
||||||
|
|
||||||
|
Blocks.init = function () {
|
||||||
|
header.init();
|
||||||
|
|
||||||
|
console.log('derpp');
|
||||||
|
};
|
||||||
|
|
||||||
|
return Blocks;
|
||||||
|
});
|
||||||
@@ -2,13 +2,22 @@
|
|||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
|
var helpers = require('../helpers');
|
||||||
var accountHelpers = require('./helpers');
|
var accountHelpers = require('./helpers');
|
||||||
|
var pagination = require('../../pagination');
|
||||||
|
var user = require('../../user');
|
||||||
|
var plugins = require('../../plugins');
|
||||||
|
|
||||||
var blocksController = {};
|
var blocksController = {};
|
||||||
|
|
||||||
blocksController.getBlocks = function (req, res, callback) {
|
blocksController.getBlocks = function (req, res, callback) {
|
||||||
var userData;
|
var userData;
|
||||||
|
|
||||||
|
var page = parseInt(req.query.page, 10) || 1;
|
||||||
|
var resultsPerPage = 50;
|
||||||
|
var start = Math.max(0, page - 1) * resultsPerPage;
|
||||||
|
var stop = start + resultsPerPage - 1;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
||||||
@@ -19,13 +28,31 @@ blocksController.getBlocks = function (req, res, callback) {
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
user.blocks.list(res.locals.uid, next);
|
||||||
},
|
},
|
||||||
], function (err) {
|
function (uids, next) {
|
||||||
|
plugins.fireHook('filter:user.getBlocks', {
|
||||||
|
uids: uids,
|
||||||
|
uid: res.locals.uid,
|
||||||
|
start: start,
|
||||||
|
stop: stop,
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
user.getUsers(data.uids, res.locals.uid, next);
|
||||||
|
},
|
||||||
|
], function (err, users) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userData.users = users;
|
||||||
|
userData.title = '[[pages:account/blocks, ' + userData.username + ']]';
|
||||||
|
var count = userData.blocksCount;
|
||||||
|
var pageCount = Math.ceil(count / resultsPerPage);
|
||||||
|
userData.pagination = pagination.create(page, pageCount);
|
||||||
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:blocks]]' }]);
|
||||||
|
|
||||||
res.render('account/blocks', userData);
|
res.render('account/blocks', userData);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
|
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
|
||||||
userData.followingCount = parseInt(userData.followingCount, 10) || 0;
|
userData.followingCount = parseInt(userData.followingCount, 10) || 0;
|
||||||
userData.followerCount = parseInt(userData.followerCount, 10) || 0;
|
userData.followerCount = parseInt(userData.followerCount, 10) || 0;
|
||||||
|
userData.blocksCount = parseInt(userData.blocksCount, 10) || 0;
|
||||||
|
|
||||||
userData.email = validator.escape(String(userData.email || ''));
|
userData.email = validator.escape(String(userData.email || ''));
|
||||||
userData.fullname = validator.escape(String(userData.fullname || ''));
|
userData.fullname = validator.escape(String(userData.fullname || ''));
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ module.exports = function (User) {
|
|||||||
|
|
||||||
User.blocks.add = function (targetUid, uid, callback) {
|
User.blocks.add = function (targetUid, uid, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
async.apply(this.stateCheck, true, targetUid, uid),
|
||||||
async.apply(db.sortedSetAdd.bind(db), 'uid:' + uid + ':blocked_uids', Date.now(), targetUid),
|
async.apply(db.sortedSetAdd.bind(db), 'uid:' + uid + ':blocked_uids', Date.now(), targetUid),
|
||||||
function (next) {
|
async.apply(User.incrementUserFieldBy, uid, 'blocksCount', 1),
|
||||||
|
function (_blank, next) {
|
||||||
User.blocks._cache.del(uid);
|
User.blocks._cache.del(uid);
|
||||||
setImmediate(next);
|
setImmediate(next);
|
||||||
},
|
},
|
||||||
@@ -48,8 +50,10 @@ module.exports = function (User) {
|
|||||||
|
|
||||||
User.blocks.remove = function (targetUid, uid, callback) {
|
User.blocks.remove = function (targetUid, uid, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
async.apply(this.stateCheck, false, targetUid, uid),
|
||||||
async.apply(db.sortedSetRemove.bind(db), 'uid:' + uid + ':blocked_uids', targetUid),
|
async.apply(db.sortedSetRemove.bind(db), 'uid:' + uid + ':blocked_uids', targetUid),
|
||||||
function (next) {
|
async.apply(User.decrementUserFieldBy, uid, 'blocksCount', 1),
|
||||||
|
function (_blank, next) {
|
||||||
User.blocks._cache.del(uid);
|
User.blocks._cache.del(uid);
|
||||||
setImmediate(next);
|
setImmediate(next);
|
||||||
},
|
},
|
||||||
@@ -57,6 +61,12 @@ module.exports = function (User) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.blocks.stateCheck = function (block, targetUid, uid, callback) {
|
||||||
|
User.blocks.is(targetUid, uid, function (err, is) {
|
||||||
|
callback(err || (is === block ? new Error('[[error:already-' + (block ? 'blocked' : 'unblocked') + ']]') : null));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
User.blocks.filter = function (uid, property, set, callback) {
|
User.blocks.filter = function (uid, property, set, callback) {
|
||||||
// Given whatever is passed in, iterates through it, and removes entries made by blocked uids
|
// Given whatever is passed in, iterates through it, and removes entries made by blocked uids
|
||||||
// property is optional
|
// property is optional
|
||||||
|
|||||||
3018
test/user.js
3018
test/user.js
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user