mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	prevent double follow/unfollow
This commit is contained in:
		| @@ -282,28 +282,24 @@ SocketUser.follow = function(socket, data, callback) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	toggleFollow('follow', socket.uid, data.uid, function(err) { | ||||
| 		if (err) { | ||||
| 			return callback(err); | ||||
| 		} | ||||
|  | ||||
| 		user.getUserFields(socket.uid, ['username', 'userslug'], function(err, userData) { | ||||
| 			if (err) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 	async.waterfall([ | ||||
| 		function(next) { | ||||
| 			toggleFollow('follow', socket.uid, data.uid, next); | ||||
| 		}, | ||||
| 		function(next) { | ||||
| 			user.getUserFields(socket.uid, ['username', 'userslug'], next); | ||||
| 		}, | ||||
| 		function(userData, next) { | ||||
| 			notifications.create({ | ||||
| 				bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]', | ||||
| 				nid: 'follow:' + data.uid + ':uid:' + socket.uid, | ||||
| 				from: socket.uid | ||||
| 			}, function(err, notification) { | ||||
| 				if (!err && notification) { | ||||
| 					notifications.push(notification, [data.uid]); | ||||
| 			}, next); | ||||
| 		}, | ||||
| 		function(notification, next) { | ||||
| 			notifications.push(notification, [data.uid], next); | ||||
| 		} | ||||
| 				callback(err); | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
| 	], callback); | ||||
| }; | ||||
|  | ||||
| SocketUser.unfollow = function(socket, data, callback) { | ||||
|   | ||||
| @@ -23,7 +23,15 @@ 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]]')); | ||||
| 				} | ||||
| 				var now = Date.now(); | ||||
| 				async.parallel([ | ||||
| 					async.apply(db.sortedSetAdd, 'following:' + uid, now, theiruid), | ||||
| @@ -32,6 +40,9 @@ module.exports = function(User) { | ||||
| 					async.apply(User.incrementUserFieldBy, theiruid, 'followerCount', 1) | ||||
| 				], callback); | ||||
| 			} else { | ||||
| 				if (!isFollowing) { | ||||
| 					return callback(new Error('[[error:not-following]]')); | ||||
| 				} | ||||
| 				async.parallel([ | ||||
| 					async.apply(db.sortedSetRemove, 'following:' + uid, theiruid), | ||||
| 					async.apply(db.sortedSetRemove, 'followers:' + theiruid, uid), | ||||
| @@ -39,6 +50,7 @@ module.exports = function(User) { | ||||
| 					async.apply(User.decrementUserFieldBy, theiruid, 'followerCount', 1) | ||||
| 				], callback); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	User.getFollowing = function(uid, start, end, callback) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user