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');
|
||||
});
|
||||
|
@ -14,9 +14,9 @@ import DriveFile from '../../../../models/drive-file';
|
||||
import Watching from '../../../../models/post-watching';
|
||||
import ChannelWatching from '../../../../models/channel-watching';
|
||||
import { pack } from '../../../../models/post';
|
||||
import notify from '../../common/notify';
|
||||
import watch from '../../common/watch-post';
|
||||
import event, { pushSw, publishChannelStream } from '../../../../common/event';
|
||||
import notify from '../../../../common/notify';
|
||||
import getAcct from '../../../../common/user/get-acct';
|
||||
import parseAcct from '../../../../common/user/parse-acct';
|
||||
import config from '../../../../conf';
|
||||
|
@ -5,9 +5,9 @@ import $ from 'cafy';
|
||||
import Vote from '../../../../../models/poll-vote';
|
||||
import Post from '../../../../../models/post';
|
||||
import Watching from '../../../../../models/post-watching';
|
||||
import notify from '../../../common/notify';
|
||||
import watch from '../../../common/watch-post';
|
||||
import { publishPostStream } from '../../../../../common/event';
|
||||
import notify from '../../../../../common/notify';
|
||||
|
||||
/**
|
||||
* Vote poll of a post
|
||||
|
@ -6,9 +6,9 @@ import Reaction from '../../../../../models/post-reaction';
|
||||
import Post, { pack as packPost } from '../../../../../models/post';
|
||||
import { pack as packUser } from '../../../../../models/user';
|
||||
import Watching from '../../../../../models/post-watching';
|
||||
import notify from '../../../common/notify';
|
||||
import watch from '../../../common/watch-post';
|
||||
import { publishPostStream, pushSw } from '../../../../../common/event';
|
||||
import notify from '../../../../../common/notify';
|
||||
|
||||
/**
|
||||
* React to a post
|
||||
|
Reference in New Issue
Block a user