From 1d8fb65959a71836f06f4f87d5fc223c56122cf2 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 8 Dec 2018 18:55:00 +0900 Subject: Fix follow duplicate (#3548) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * フォローとリクエスト両方存在しても解除する * 既にフォローしてても承認できるように --- src/remote/activitypub/kernel/undo/follow.ts | 10 +++++++++- 1 file changed, 9 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 f112ee8bfb..af06aa5b31 100644 --- a/src/remote/activitypub/kernel/undo/follow.ts +++ b/src/remote/activitypub/kernel/undo/follow.ts @@ -5,6 +5,7 @@ import unfollow from '../../../../services/following/delete'; import cancelRequest from '../../../../services/following/requests/cancel'; import { IFollow } from '../../type'; import FollowRequest from '../../../../models/follow-request'; +import Following from '../../../../models/following'; export default async (actor: IRemoteUser, activity: IFollow): Promise => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; @@ -30,9 +31,16 @@ export default async (actor: IRemoteUser, activity: IFollow): Promise => { followeeId: followee._id }); + const following = await Following.findOne({ + followerId: actor._id, + followeeId: followee._id + }); + if (req) { await cancelRequest(followee, actor); - } else { + } + + if (following) { await unfollow(actor, followee); } }; -- cgit v1.2.3-freya