From cfd19c23a1cfe920d3af4a7f469edf7821ef0a70 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 11 Feb 2019 23:37:15 +0900 Subject: [PATCH] Fix bug --- src/services/following/create.ts | 10 +++++++++- src/services/following/requests/accept.ts | 6 ------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/following/create.ts b/src/services/following/create.ts index e6c95a72a..a050f40b0 100644 --- a/src/services/following/create.ts +++ b/src/services/following/create.ts @@ -46,11 +46,19 @@ export async function insertFollowingDoc(followee: IUser, follower: IUser) { } }); - await FollowRequest.remove({ + const removed = await FollowRequest.remove({ followeeId: followee._id, followerId: follower._id }); + if (removed.deletedCount === 1) { + await User.update({ _id: followee._id }, { + $inc: { + pendingReceivedFollowRequestsCount: -1 + } + }); + } + if (alreadyFollowed) return; //#region Increment counts diff --git a/src/services/following/requests/accept.ts b/src/services/following/requests/accept.ts index 81ecc74ab..dec30911a 100644 --- a/src/services/following/requests/accept.ts +++ b/src/services/following/requests/accept.ts @@ -20,12 +20,6 @@ export default async function(followee: IUser, follower: IUser) { deliver(followee as ILocalUser, content, follower.inbox); } - await User.update({ _id: followee._id }, { - $inc: { - pendingReceivedFollowRequestsCount: -1 - } - }); - packUser(followee, followee, { detail: true }).then(packed => publishMainStream(followee._id, 'meUpdated', packed));