From 4b507ed349496fbd7fafc7913bd299763fed827c Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 3 Apr 2018 17:18:06 +0900 Subject: Implement remote account unfollow --- src/remote/activitypub/act/undo/index.ts | 2 +- src/remote/activitypub/act/undo/unfollow.ts | 33 +++++++++-------------------- src/remote/activitypub/renderer/undo.ts | 4 ++++ 3 files changed, 15 insertions(+), 24 deletions(-) create mode 100644 src/remote/activitypub/renderer/undo.ts (limited to 'src/remote/activitypub') diff --git a/src/remote/activitypub/act/undo/index.ts b/src/remote/activitypub/act/undo/index.ts index b43ae86173..c34d56e704 100644 --- a/src/remote/activitypub/act/undo/index.ts +++ b/src/remote/activitypub/act/undo/index.ts @@ -15,7 +15,7 @@ export default async (resolver, actor, activity) => { switch (result.object.$ref) { case 'following': - await unfollow(result.resolver, result.object); + await unfollow(result.object); } })); diff --git a/src/remote/activitypub/act/undo/unfollow.ts b/src/remote/activitypub/act/undo/unfollow.ts index 0523699bfe..c17e06e8a9 100644 --- a/src/remote/activitypub/act/undo/unfollow.ts +++ b/src/remote/activitypub/act/undo/unfollow.ts @@ -1,24 +1,11 @@ -import FollowedLog from '../../../../models/followed-log'; -import Following from '../../../../models/following'; -import FollowingLog from '../../../../models/following-log'; -import User from '../../../../models/user'; +import queue from '../../../../queue'; -export default async (resolver, { $id }) => { - const following = await Following.findOneAndDelete({ _id: $id }); - if (following === null) { - return; - } - - await Promise.all([ - User.update({ _id: following.followerId }, { $inc: { followingCount: -1 } }), - User.findOne({ _id: following.followerId }).then(({ followingCount }) => FollowingLog.insert({ - userId: following.followerId, - count: followingCount - 1 - })), - User.update({ _id: following.followeeId }, { $inc: { followersCount: -1 } }), - User.findOne({ _id: following.followeeId }).then(({ followersCount }) => FollowedLog.insert({ - userId: following.followeeId, - count: followersCount - 1 - })), - ]); -}; +export default ({ $id }) => new Promise((resolve, reject) => { + queue.create('http', { type: 'unfollow', id: $id }).save(error => { + if (error) { + reject(error); + } else { + resolve(); + } + }); +}); diff --git a/src/remote/activitypub/renderer/undo.ts b/src/remote/activitypub/renderer/undo.ts new file mode 100644 index 0000000000..f38e224b60 --- /dev/null +++ b/src/remote/activitypub/renderer/undo.ts @@ -0,0 +1,4 @@ +export default object => ({ + type: 'Undo', + object +}); -- cgit v1.2.3-freya