From f14571dc42532c269e606f810ec2af03a3baeba5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 2 Jun 2018 00:38:31 +0900 Subject: wip --- src/remote/activitypub/kernel/undo/follow.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/remote/activitypub/kernel') diff --git a/src/remote/activitypub/kernel/undo/follow.ts b/src/remote/activitypub/kernel/undo/follow.ts index 763d5723c4..7377984616 100644 --- a/src/remote/activitypub/kernel/undo/follow.ts +++ b/src/remote/activitypub/kernel/undo/follow.ts @@ -2,7 +2,9 @@ import * as mongo from 'mongodb'; import User, { IRemoteUser } from '../../../../models/user'; import config from '../../../../config'; import unfollow from '../../../../services/following/delete'; +import cancelRequest from '../../../../services/following/requests/cancel'; import { IFollow } from '../../type'; +import FollowRequest from '../../../../models/follow-request'; export default async (actor: IRemoteUser, activity: IFollow): Promise => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; @@ -23,5 +25,14 @@ export default async (actor: IRemoteUser, activity: IFollow): Promise => { throw new Error('フォロー解除しようとしているユーザーはローカルユーザーではありません'); } - await unfollow(actor, followee); + const req = await FollowRequest.findOne({ + followerId: actor._id, + followeeId: followee._id + }); + + if (req) { + await cancelRequest(actor, followee); + } else { + await unfollow(actor, followee); + } }; -- cgit v1.2.3-freya