Implement remote follow
This commit is contained in:
		@@ -2,10 +2,9 @@
 | 
			
		||||
 * Module dependencies
 | 
			
		||||
 */
 | 
			
		||||
import $ from 'cafy';
 | 
			
		||||
import User, { pack as packUser } from '../../../../models/user';
 | 
			
		||||
import User from '../../../../models/user';
 | 
			
		||||
import Following from '../../../../models/following';
 | 
			
		||||
import notify from '../../common/notify';
 | 
			
		||||
import event from '../../../../common/event';
 | 
			
		||||
import queue from '../../../../queue';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Follow a user
 | 
			
		||||
@@ -52,33 +51,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Create following
 | 
			
		||||
	await Following.insert({
 | 
			
		||||
	const { _id } = await Following.insert({
 | 
			
		||||
		createdAt: new Date(),
 | 
			
		||||
		followerId: follower._id,
 | 
			
		||||
		followeeId: followee._id
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	queue.create('http', { type: 'follow', following: _id }).save();
 | 
			
		||||
 | 
			
		||||
	// Send response
 | 
			
		||||
	res();
 | 
			
		||||
 | 
			
		||||
	// Increment following count
 | 
			
		||||
	User.update(follower._id, {
 | 
			
		||||
		$inc: {
 | 
			
		||||
			followingCount: 1
 | 
			
		||||
		}
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	// Increment followers count
 | 
			
		||||
	User.update({ _id: followee._id }, {
 | 
			
		||||
		$inc: {
 | 
			
		||||
			followersCount: 1
 | 
			
		||||
		}
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	// Publish follow event
 | 
			
		||||
	event(follower._id, 'follow', await packUser(followee, follower));
 | 
			
		||||
	event(followee._id, 'followed', await packUser(follower, followee));
 | 
			
		||||
 | 
			
		||||
	// Notify
 | 
			
		||||
	notify(followee._id, follower._id, 'follow');
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user