summaryrefslogtreecommitdiff
path: root/src/queue/processors/http/follow.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-04-07 16:26:50 +0900
committerGitHub <noreply@github.com>2018-04-07 16:26:50 +0900
commit2547891f940a2872fcfb2b33cd33d4f7a42ca7bc (patch)
tree5cba4ae9cdfd63e7e1ef74a002a7b742183e8d3c /src/queue/processors/http/follow.ts
parentMerge pull request #1410 from akihikodaki/objec (diff)
parentRefactor (diff)
downloadmisskey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.tar.gz
misskey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.tar.bz2
misskey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.zip
Merge pull request #1397 from syuilo/refactor
Refactor
Diffstat (limited to 'src/queue/processors/http/follow.ts')
-rw-r--r--src/queue/processors/http/follow.ts66
1 files changed, 0 insertions, 66 deletions
diff --git a/src/queue/processors/http/follow.ts b/src/queue/processors/http/follow.ts
deleted file mode 100644
index ba1cc31186..0000000000
--- a/src/queue/processors/http/follow.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import User, { isLocalUser, isRemoteUser, pack as packUser } from '../../../models/user';
-import Following from '../../../models/following';
-import FollowingLog from '../../../models/following-log';
-import FollowedLog from '../../../models/followed-log';
-import event from '../../../publishers/stream';
-import notify from '../../../publishers/notify';
-import context from '../../../remote/activitypub/renderer/context';
-import render from '../../../remote/activitypub/renderer/follow';
-import request from '../../../remote/request';
-
-export default ({ data }, done) => Following.findOne({ _id: data.following }).then(async ({ followerId, followeeId }) => {
- const [follower, followee] = await Promise.all([
- User.findOne({ _id: followerId }),
- User.findOne({ _id: followeeId })
- ]);
-
- if (isLocalUser(follower) && isRemoteUser(followee)) {
- const rendered = render(follower, followee);
- rendered['@context'] = context;
-
- await request(follower, followee.account.inbox, rendered);
- }
-
- return [follower, followee];
-}).then(([follower, followee]) => Promise.all([
- // Increment following count
- User.update(follower._id, {
- $inc: {
- followingCount: 1
- }
- }),
-
- FollowingLog.insert({
- createdAt: data.following.createdAt,
- userId: follower._id,
- count: follower.followingCount + 1
- }),
-
- // Increment followers count
- User.update({ _id: followee._id }, {
- $inc: {
- followersCount: 1
- }
- }),
-
- FollowedLog.insert({
- createdAt: data.following.createdAt,
- userId: follower._id,
- count: followee.followersCount + 1
- }),
-
- // Publish follow event
- isLocalUser(follower) && packUser(followee, follower)
- .then(packed => event(follower._id, 'follow', packed)),
-
- isLocalUser(followee) && Promise.all([
- packUser(follower, followee)
- .then(packed => event(followee._id, 'followed', packed)),
-
- // Notify
- isLocalUser(followee) && notify(followee._id, follower._id, 'follow')
- ])
-]).then(() => done(), error => {
- done();
- throw error;
-}), done);