diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2018-04-15 18:12:11 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-15 18:12:11 +0900 |
| commit | f982f5e850d1096d54014396b3ee9d337e305bcb (patch) | |
| tree | 0dae4116aa5d7c3fe6c5eba54af6f9f15a271761 /src/models | |
| parent | Merge pull request #4 from syuilo/master (diff) | |
| parent | nanka iroiro (diff) | |
| download | misskey-f982f5e850d1096d54014396b3ee9d337e305bcb.tar.gz misskey-f982f5e850d1096d54014396b3ee9d337e305bcb.tar.bz2 misskey-f982f5e850d1096d54014396b3ee9d337e305bcb.zip | |
Merge pull request #5 from syuilo/master
追従
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/drive-file.ts | 9 | ||||
| -rw-r--r-- | src/models/note.ts | 16 | ||||
| -rw-r--r-- | src/models/notification.ts | 27 | ||||
| -rw-r--r-- | src/models/user.ts | 23 |
4 files changed, 67 insertions, 8 deletions
diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts index 80fe8e0300..fc9c150724 100644 --- a/src/models/drive-file.ts +++ b/src/models/drive-file.ts @@ -84,14 +84,19 @@ export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriv // このDriveFileがアバターやバナーに使われていたらそれらのプロパティをnullにする const u = await User.findOne({ _id: d.metadata.userId }); if (u) { - if (u.avatarId.equals(d._id)) { + if (u.avatarId && u.avatarId.equals(d._id)) { await User.update({ _id: u._id }, { $set: { avatarId: null } }); } - if (u.bannerId.equals(d._id)) { + if (u.bannerId && u.bannerId.equals(d._id)) { await User.update({ _id: u._id }, { $set: { bannerId: null } }); } } + // このDriveFileのチャンクをすべて削除 + await monkDb.get('driveFiles.chunks').remove({ + files_id: d._id + }); + // このDriveFileを削除 await DriveFile.remove({ _id: d._id diff --git a/src/models/note.ts b/src/models/note.ts index 3c1c2e18e1..3059593540 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -5,13 +5,13 @@ import db from '../db/mongodb'; import { IUser, pack as packUser } from './user'; import { pack as packApp } from './app'; import { pack as packChannel } from './channel'; -import Vote, { deletePollVote } from './poll-vote'; +import PollVote, { deletePollVote } from './poll-vote'; import Reaction, { deleteNoteReaction } from './note-reaction'; import { pack as packFile } from './drive-file'; import NoteWatching, { deleteNoteWatching } from './note-watching'; import NoteReaction from './note-reaction'; import Favorite, { deleteFavorite } from './favorite'; -import PollVote from './poll-vote'; +import Notification, { deleteNotification } from './notification'; const Note = db.get<INote>('notes'); @@ -66,7 +66,6 @@ export type INote = { }; _user: { host: string; - hostLower: string; account: { inbox?: string; }; @@ -92,6 +91,8 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { n = note as INote; } + console.log(n == null ? `Note: delete skipped ${note}` : `Note: deleting ${n._id}`); + if (n == null) return; // このNoteへの返信をすべて削除 @@ -124,10 +125,17 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { await Favorite.find({ noteId: n._id }) ).map(x => deleteFavorite(x))); + // この投稿に対するNotificationをすべて削除 + await Promise.all(( + await Notification.find({ noteId: n._id }) + ).map(x => deleteNotification(x))); + // このNoteを削除 await Note.remove({ _id: n._id }); + + console.log(`Note: deleted ${n._id}`); } /** @@ -259,7 +267,7 @@ export const pack = async ( // Poll if (meId && _note.poll) { _note.poll = (async (poll) => { - const vote = await Vote + const vote = await PollVote .findOne({ userId: meId, noteId: id diff --git a/src/models/notification.ts b/src/models/notification.ts index d5ca7135b7..76871166a9 100644 --- a/src/models/notification.ts +++ b/src/models/notification.ts @@ -50,6 +50,33 @@ export interface INotification { } /** + * Notificationを物理削除します + */ +export async function deleteNotification(notification: string | mongo.ObjectID | INotification) { + let n: INotification; + + // Populate + if (mongo.ObjectID.prototype.isPrototypeOf(notification)) { + n = await Notification.findOne({ + _id: notification + }); + } else if (typeof notification === 'string') { + n = await Notification.findOne({ + _id: new mongo.ObjectID(notification) + }); + } else { + n = notification as INotification; + } + + if (n == null) return; + + // このNotificationを削除 + await Notification.remove({ + _id: n._id + }); +} + +/** * Pack a notification for API response */ export const pack = (notification: any) => new Promise<any>(async (resolve, reject) => { diff --git a/src/models/user.ts b/src/models/user.ts index c121790c31..1d23c21dbd 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -19,12 +19,15 @@ import PollVote, { deletePollVote } from './poll-vote'; import FollowingLog, { deleteFollowingLog } from './following-log'; import FollowedLog, { deleteFollowedLog } from './followed-log'; import SwSubscription, { deleteSwSubscription } from './sw-subscription'; +import Notification, { deleteNotification } from './notification'; const User = db.get<IUser>('users'); User.createIndex('username'); User.createIndex('usernameLower'); -User.createIndex('token'); +User.createIndex(['username', 'host'], { unique: true }); +User.createIndex(['usernameLower', 'host'], { unique: true }); +User.createIndex('token', { sparse: true, unique: true }); User.createIndex('uri', { sparse: true, unique: true }); export default User; @@ -49,7 +52,6 @@ type IUserBase = { isSuspended: boolean; keywords: string[]; host: string; - hostLower: string; }; export interface ILocalUser extends IUserBase { @@ -153,6 +155,8 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { u = user as IUser; } + console.log(u == null ? `User: delete skipped ${user}` : `User: deleting ${u._id}`); + if (u == null) return; // このユーザーのAccessTokenをすべて削除 @@ -245,7 +249,22 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { await SwSubscription.find({ userId: u._id }) ).map(x => deleteSwSubscription(x))); + // このユーザーのNotificationをすべて削除 + await Promise.all(( + await Notification.find({ notifieeId: u._id }) + ).map(x => deleteNotification(x))); + + // このユーザーが原因となったNotificationをすべて削除 + await Promise.all(( + await Notification.find({ notifierId: u._id }) + ).map(x => deleteNotification(x))); + // このユーザーを削除 + await User.remove({ + _id: u._id + }); + + console.log(`User: deleted ${u._id}`); } /** |