From b34b728fbb1dc2693230e6d3b3d6b468ac48396f Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 9 Nov 2019 18:24:41 +0900 Subject: [PATCH] Resolve #5587 (#5588) * Resolve #5587 * stat --- src/services/following/delete.ts | 28 +++++++++++++---------- src/services/following/requests/reject.ts | 19 +++++++++++++-- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/services/following/delete.ts b/src/services/following/delete.ts index e3b5f8c41..882161151 100644 --- a/src/services/following/delete.ts +++ b/src/services/following/delete.ts @@ -24,6 +24,22 @@ export default async function(follower: User, followee: User, silent = false) { await Followings.delete(following.id); + decrementFollowing(follower, followee); + + // Publish unfollow event + if (!silent && Users.isLocalUser(follower)) { + Users.pack(followee, follower, { + detail: true + }).then(packed => publishMainStream(follower.id, 'unfollow', packed)); + } + + if (Users.isLocalUser(follower) && Users.isRemoteUser(followee)) { + const content = renderActivity(renderUndo(renderFollow(follower, followee), follower)); + deliver(follower, content, followee.inbox); + } +} + +export async function decrementFollowing(follower: User, followee: User) { //#region Decrement following count Users.decrement({ id: follower.id }, 'followingCount', 1); //#endregion @@ -47,16 +63,4 @@ export default async function(follower: User, followee: User, silent = false) { //#endregion perUserFollowingChart.update(follower, followee, false); - - // Publish unfollow event - if (!silent && Users.isLocalUser(follower)) { - Users.pack(followee, follower, { - detail: true - }).then(packed => publishMainStream(follower.id, 'unfollow', packed)); - } - - if (Users.isLocalUser(follower) && Users.isRemoteUser(followee)) { - const content = renderActivity(renderUndo(renderFollow(follower, followee), follower)); - deliver(follower, content, followee.inbox); - } } diff --git a/src/services/following/requests/reject.ts b/src/services/following/requests/reject.ts index d5b5e48c4..9a8b14bbf 100644 --- a/src/services/following/requests/reject.ts +++ b/src/services/following/requests/reject.ts @@ -4,7 +4,8 @@ import renderReject from '../../../remote/activitypub/renderer/reject'; import { deliver } from '../../../queue'; import { publishMainStream } from '../../stream'; import { User, ILocalUser } from '../../../models/entities/user'; -import { Users, FollowRequests } from '../../../models'; +import { Users, FollowRequests, Followings } from '../../../models'; +import { decrementFollowing } from '../delete'; export default async function(followee: User, follower: User) { if (Users.isRemoteUser(follower)) { @@ -17,11 +18,25 @@ export default async function(followee: User, follower: User) { deliver(followee as ILocalUser, content, follower.inbox); } - await FollowRequests.delete({ + const request = await FollowRequests.findOne({ followeeId: followee.id, followerId: follower.id }); + if (request) { + await FollowRequests.delete(request.id); + } else { + const following = await Followings.findOne({ + followeeId: followee.id, + followerId: follower.id + }); + + if (following) { + await Followings.delete(following.id); + decrementFollowing(follower, followee); + } + } + Users.pack(followee, follower, { detail: true }).then(packed => publishMainStream(follower.id, 'unfollow', packed));