From b846eb8afe0376feacb567e86bf157b8fd5f4c36 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 12 Apr 2018 05:50:45 +0900 Subject: [PATCH] wip --- src/models/mute.ts | 27 +++++++++++++++++++++++++++ src/models/user.ts | 16 +++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/models/mute.ts b/src/models/mute.ts index 8793615967..e068215c94 100644 --- a/src/models/mute.ts +++ b/src/models/mute.ts @@ -11,3 +11,30 @@ export interface IMute { muterId: mongo.ObjectID; muteeId: mongo.ObjectID; } + +/** + * Muteを物理削除します + */ +export async function deleteMute(mute: string | mongo.ObjectID | IMute) { + let m: IMute; + + // Populate + if (mongo.ObjectID.prototype.isPrototypeOf(mute)) { + m = await Mute.findOne({ + _id: mute + }); + } else if (typeof mute === 'string') { + m = await Mute.findOne({ + _id: new mongo.ObjectID(mute) + }); + } else { + m = mute as IMute; + } + + if (m == null) return; + + // このMuteを削除 + await Mute.remove({ + _id: m._id + }); +} diff --git a/src/models/user.ts b/src/models/user.ts index b56cf03ef8..ff1c11e76c 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -4,7 +4,7 @@ import rap from '@prezzemolo/rap'; import db from '../db/mongodb'; import Note, { INote, pack as packNote, deleteNote } from './note'; import Following from './following'; -import Mute from './mute'; +import Mute, { deleteMute } from './mute'; import getFriends from '../server/api/common/get-friends'; import config from '../config'; import AccessToken, { deleteAccessToken } from './access-token'; @@ -201,10 +201,24 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { await DriveFolder.find({ userId: u._id }) ).map(x => deleteDriveFolder(x))); + // このユーザーのMuteをすべて削除 + await Promise.all(( + await Mute.find({ muterId: u._id }) + ).map(x => deleteMute(x))); + + // このユーザーへのMuteをすべて削除 + await Promise.all(( + await Mute.find({ muteeId: u._id }) + ).map(x => deleteMute(x))); + // このユーザーのFollowingをすべて削除 // このユーザーへのFollowingをすべて削除 + // このユーザーのFollowingLogをすべて削除 + + // このユーザーのFollowedLogをすべて削除 + // このユーザーを削除 }