|
|
@ -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
|
|
|
|