mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-25 20:32:07 +02:00
Merge remote-tracking branch 'origin/master' into user-icons
Conflicts: public/src/app.js public/src/client/account/edit.js
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
var async = require('async');
|
||||
|
||||
var db = require('../database');
|
||||
var categories = require('../categories');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
@@ -34,13 +35,35 @@ module.exports = function(User) {
|
||||
if (!uid) {
|
||||
return callback();
|
||||
}
|
||||
db.sortedSetAdd('uid:' + uid + ':ignored:cids', Date.now(), cid, callback);
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.exists(cid, next);
|
||||
},
|
||||
function (exists, next) {
|
||||
if (!exists) {
|
||||
return next(new Error('[[error:no-category]]'));
|
||||
}
|
||||
db.sortedSetAdd('uid:' + uid + ':ignored:cids', Date.now(), cid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.watchCategory = function(uid, cid, callback) {
|
||||
if (!uid) {
|
||||
return callback();
|
||||
}
|
||||
db.sortedSetRemove('uid:' + uid + ':ignored:cids', cid, callback);
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.exists(cid, next);
|
||||
},
|
||||
function (exists, next) {
|
||||
if (!exists) {
|
||||
return next(new Error('[[error:no-category]]'));
|
||||
}
|
||||
db.sortedSetRemove('uid:' + uid + ':ignored:cids', cid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
@@ -198,7 +198,7 @@ module.exports = function(User) {
|
||||
var newUsername = '';
|
||||
async.forever(function(next) {
|
||||
newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);
|
||||
User.exists(newUsername, function(err, exists) {
|
||||
User.existsBySlug(newUsername, function(err, exists) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
var async = require('async'),
|
||||
plugins = require('../plugins'),
|
||||
db = require('./../database');
|
||||
db = require('../database');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
@@ -24,34 +24,41 @@ module.exports = function(User) {
|
||||
return callback(new Error('[[error:you-cant-follow-yourself]]'));
|
||||
}
|
||||
|
||||
User.isFollowing(uid, theiruid, function(err, isFollowing) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (type === 'follow') {
|
||||
if (isFollowing) {
|
||||
return callback(new Error('[[error:already-following]]'));
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
User.exists(theiruid, next);
|
||||
},
|
||||
function (exists, next) {
|
||||
if (!exists) {
|
||||
return next(new Error('[[error:no-user]]'));
|
||||
}
|
||||
var now = Date.now();
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetAdd, 'following:' + uid, now, theiruid),
|
||||
async.apply(db.sortedSetAdd, 'followers:' + theiruid, now, uid),
|
||||
async.apply(User.incrementUserFieldBy, uid, 'followingCount', 1),
|
||||
async.apply(User.incrementUserFieldBy, theiruid, 'followerCount', 1)
|
||||
], callback);
|
||||
} else {
|
||||
if (!isFollowing) {
|
||||
return callback(new Error('[[error:not-following]]'));
|
||||
User.isFollowing(uid, theiruid, next);
|
||||
},
|
||||
function (isFollowing, next) {
|
||||
if (type === 'follow') {
|
||||
if (isFollowing) {
|
||||
return next(new Error('[[error:already-following]]'));
|
||||
}
|
||||
var now = Date.now();
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetAdd, 'following:' + uid, now, theiruid),
|
||||
async.apply(db.sortedSetAdd, 'followers:' + theiruid, now, uid),
|
||||
async.apply(User.incrementUserFieldBy, uid, 'followingCount', 1),
|
||||
async.apply(User.incrementUserFieldBy, theiruid, 'followerCount', 1)
|
||||
], next);
|
||||
} else {
|
||||
if (!isFollowing) {
|
||||
return next(new Error('[[error:not-following]]'));
|
||||
}
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetRemove, 'following:' + uid, theiruid),
|
||||
async.apply(db.sortedSetRemove, 'followers:' + theiruid, uid),
|
||||
async.apply(User.decrementUserFieldBy, uid, 'followingCount', 1),
|
||||
async.apply(User.decrementUserFieldBy, theiruid, 'followerCount', 1)
|
||||
], next);
|
||||
}
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetRemove, 'following:' + uid, theiruid),
|
||||
async.apply(db.sortedSetRemove, 'followers:' + theiruid, uid),
|
||||
async.apply(User.decrementUserFieldBy, uid, 'followingCount', 1),
|
||||
async.apply(User.decrementUserFieldBy, theiruid, 'followerCount', 1)
|
||||
], callback);
|
||||
}
|
||||
});
|
||||
], callback);
|
||||
}
|
||||
|
||||
User.getFollowing = function(uid, start, stop, callback) {
|
||||
|
||||
@@ -71,10 +71,13 @@ module.exports = function(User) {
|
||||
return next();
|
||||
}
|
||||
User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var userslug = utils.slugify(data.username);
|
||||
|
||||
if(userslug === userData.userslug) {
|
||||
if (userslug === userData.userslug) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -86,12 +89,12 @@ module.exports = function(User) {
|
||||
return next(new Error('[[error:username-too-long]]'));
|
||||
}
|
||||
|
||||
if(!utils.isUserNameValid(data.username) || !userslug) {
|
||||
if (!utils.isUserNameValid(data.username) || !userslug) {
|
||||
return next(new Error('[[error:invalid-username]]'));
|
||||
}
|
||||
|
||||
User.exists(userslug, function(err, exists) {
|
||||
if(err) {
|
||||
User.existsBySlug(userslug, function(err, exists) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user