This commit is contained in:
syuilo 2018-04-12 05:50:45 +09:00
parent 53415e9ba4
commit b846eb8afe
2 changed files with 42 additions and 1 deletions

View file

@ -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
});
}

View file

@ -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をすべて削除
// このユーザーを削除
}