From b323a160e3c2cd3201a4be193e28957f3b58af85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Thu, 14 Mar 2019 01:20:25 +0900 Subject: [PATCH 1/2] Follow #3676 --- src/remote/logger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/remote/logger.ts b/src/remote/logger.ts index 43b4f105aa..d7464e7fde 100644 --- a/src/remote/logger.ts +++ b/src/remote/logger.ts @@ -1,3 +1,3 @@ -import Logger from "../services/logger"; +import Logger from '../services/logger'; export const remoteLogger = new Logger('remote', 'cyan'); From 1179920790f2d4926eeb17368c3895b5321936d6 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Thu, 14 Mar 2019 15:16:07 +0900 Subject: [PATCH 2/2] unFollowAll on suspend (#4490) * unFollowAll on suspend * use services * silent --- .../api/endpoints/admin/suspend-user.ts | 24 ++++++++++++++++++- src/services/following/delete.ts | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/server/api/endpoints/admin/suspend-user.ts b/src/server/api/endpoints/admin/suspend-user.ts index 83b39fb0b9..0a2d309530 100644 --- a/src/server/api/endpoints/admin/suspend-user.ts +++ b/src/server/api/endpoints/admin/suspend-user.ts @@ -1,7 +1,9 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import define from '../../define'; -import User from '../../../../models/user'; +import User, { IUser } from '../../../../models/user'; +import Following from '../../../../models/following'; +import deleteFollowing from '../../../../services/following/delete'; export const meta = { desc: { @@ -51,5 +53,25 @@ export default define(meta, async (ps) => { } }); + unFollowAll(user); + return; }); + +async function unFollowAll(follower: IUser) { + const followings = await Following.find({ + followerId: follower._id + }); + + for (const following of followings) { + const followee = await User.findOne({ + _id: following.followeeId + }); + + if (followee == null) { + throw `Cant find followee ${following.followeeId}`; + } + + await deleteFollowing(follower, followee, true); + } +} diff --git a/src/services/following/delete.ts b/src/services/following/delete.ts index 28268f1fd8..d85c8472bb 100644 --- a/src/services/following/delete.ts +++ b/src/services/following/delete.ts @@ -13,7 +13,7 @@ import instanceChart from '../../services/chart/instance'; const logger = new Logger('following/delete'); -export default async function(follower: IUser, followee: IUser) { +export default async function(follower: IUser, followee: IUser, silent = false) { const following = await Following.findOne({ followerId: follower._id, followeeId: followee._id @@ -71,7 +71,7 @@ export default async function(follower: IUser, followee: IUser) { perUserFollowingChart.update(follower, followee, false); // Publish unfollow event - if (isLocalUser(follower)) { + if (!silent && isLocalUser(follower)) { packUser(followee, follower, { detail: true }).then(packed => publishMainStream(follower._id, 'unfollow', packed));