summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-12 03:46:32 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-12 03:46:32 +0900
commit553fccd719690a659f5985e7956e875af92d17e0 (patch)
treeb70092f1a19aa5a7a72fe85146a1f9b49443384c
parentMerge branch 'master' of https://github.com/syuilo/misskey (diff)
downloadmisskey-553fccd719690a659f5985e7956e875af92d17e0.tar.gz
misskey-553fccd719690a659f5985e7956e875af92d17e0.tar.bz2
misskey-553fccd719690a659f5985e7956e875af92d17e0.zip
wip
-rw-r--r--src/models/access-token.ts31
-rw-r--r--src/models/favorite.ts31
-rw-r--r--src/models/note-reaction.ts31
-rw-r--r--src/models/note-watching.ts27
-rw-r--r--src/models/note.ts43
-rw-r--r--src/models/user.ts49
6 files changed, 184 insertions, 28 deletions
diff --git a/src/models/access-token.ts b/src/models/access-token.ts
index 4451ca140d..9909ea01ad 100644
--- a/src/models/access-token.ts
+++ b/src/models/access-token.ts
@@ -1,12 +1,12 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-const AccessToken = db.get<IAccessTokens>('accessTokens');
+const AccessToken = db.get<IAccessToken>('accessTokens');
AccessToken.createIndex('token');
AccessToken.createIndex('hash');
export default AccessToken;
-export type IAccessTokens = {
+export type IAccessToken = {
_id: mongo.ObjectID;
createdAt: Date;
appId: mongo.ObjectID;
@@ -14,3 +14,30 @@ export type IAccessTokens = {
token: string;
hash: string;
};
+
+/**
+ * AccessTokenを物理削除します
+ */
+export async function deleteAccessToken(accessToken: string | mongo.ObjectID | IAccessToken) {
+ let a: IAccessToken;
+
+ // Populate
+ if (mongo.ObjectID.prototype.isPrototypeOf(accessToken)) {
+ a = await AccessToken.findOne({
+ _id: accessToken
+ });
+ } else if (typeof accessToken === 'string') {
+ a = await AccessToken.findOne({
+ _id: new mongo.ObjectID(accessToken)
+ });
+ } else {
+ a = accessToken as IAccessToken;
+ }
+
+ if (a == null) return;
+
+ // このAccessTokenを削除
+ await AccessToken.remove({
+ _id: a._id
+ });
+}
diff --git a/src/models/favorite.ts b/src/models/favorite.ts
index 73f8881926..b2c5828088 100644
--- a/src/models/favorite.ts
+++ b/src/models/favorite.ts
@@ -1,8 +1,8 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-const Favorites = db.get<IFavorite>('favorites');
-export default Favorites;
+const Favorite = db.get<IFavorite>('favorites');
+export default Favorite;
export type IFavorite = {
_id: mongo.ObjectID;
@@ -10,3 +10,30 @@ export type IFavorite = {
userId: mongo.ObjectID;
noteId: mongo.ObjectID;
};
+
+/**
+ * Favoriteを物理削除します
+ */
+export async function deleteFavorite(favorite: string | mongo.ObjectID | IFavorite) {
+ let f: IFavorite;
+
+ // Populate
+ if (mongo.ObjectID.prototype.isPrototypeOf(favorite)) {
+ f = await Favorite.findOne({
+ _id: favorite
+ });
+ } else if (typeof favorite === 'string') {
+ f = await Favorite.findOne({
+ _id: new mongo.ObjectID(favorite)
+ });
+ } else {
+ f = favorite as IFavorite;
+ }
+
+ if (f == null) return;
+
+ // このFavoriteを削除
+ await Favorite.remove({
+ _id: f._id
+ });
+}
diff --git a/src/models/note-reaction.ts b/src/models/note-reaction.ts
index d499442de9..9bf467f222 100644
--- a/src/models/note-reaction.ts
+++ b/src/models/note-reaction.ts
@@ -17,11 +17,34 @@ export interface INoteReaction {
}
/**
+ * NoteReactionを物理削除します
+ */
+export async function deleteNoteReaction(noteReaction: string | mongo.ObjectID | INoteReaction) {
+ let n: INoteReaction;
+
+ // Populate
+ if (mongo.ObjectID.prototype.isPrototypeOf(noteReaction)) {
+ n = await NoteReaction.findOne({
+ _id: noteReaction
+ });
+ } else if (typeof noteReaction === 'string') {
+ n = await NoteReaction.findOne({
+ _id: new mongo.ObjectID(noteReaction)
+ });
+ } else {
+ n = noteReaction as INoteReaction;
+ }
+
+ if (n == null) return;
+
+ // このNoteReactionを削除
+ await NoteReaction.remove({
+ _id: n._id
+ });
+}
+
+/**
* Pack a reaction for API response
- *
- * @param {any} reaction
- * @param {any} me?
- * @return {Promise<any>}
*/
export const pack = (
reaction: any,
diff --git a/src/models/note-watching.ts b/src/models/note-watching.ts
index b5ef3b61b7..479f92dd44 100644
--- a/src/models/note-watching.ts
+++ b/src/models/note-watching.ts
@@ -11,3 +11,30 @@ export interface INoteWatching {
userId: mongo.ObjectID;
noteId: mongo.ObjectID;
}
+
+/**
+ * NoteWatchingを物理削除します
+ */
+export async function deleteNoteWatching(noteWatching: string | mongo.ObjectID | INoteWatching) {
+ let n: INoteWatching;
+
+ // Populate
+ if (mongo.ObjectID.prototype.isPrototypeOf(noteWatching)) {
+ n = await NoteWatching.findOne({
+ _id: noteWatching
+ });
+ } else if (typeof noteWatching === 'string') {
+ n = await NoteWatching.findOne({
+ _id: new mongo.ObjectID(noteWatching)
+ });
+ } else {
+ n = noteWatching as INoteWatching;
+ }
+
+ if (n == null) return;
+
+ // このNoteWatchingを削除
+ await NoteWatching.remove({
+ _id: n._id
+ });
+}
diff --git a/src/models/note.ts b/src/models/note.ts
index a11da196cd..6e7b6cee79 100644
--- a/src/models/note.ts
+++ b/src/models/note.ts
@@ -6,8 +6,11 @@ import { IUser, pack as packUser } from './user';
import { pack as packApp } from './app';
import { pack as packChannel } from './channel';
import Vote from './poll-vote';
-import Reaction from './note-reaction';
+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';
const Note = db.get<INote>('notes');
@@ -69,8 +72,10 @@ export type INote = {
};
};
-// TODO
-export async function physicalDelete(note: string | mongo.ObjectID | INote) {
+/**
+ * Noteを物理削除します
+ */
+export async function deleteNote(note: string | mongo.ObjectID | INote) {
let n: INote;
// Populate
@@ -88,17 +93,35 @@ export async function physicalDelete(note: string | mongo.ObjectID | INote) {
if (n == null) return;
- // この投稿の返信をすべて削除
- const replies = await Note.find({
- replyId: n._id
- });
- await Promise.all(replies.map(r => physicalDelete(r)));
+ // このNoteへの返信をすべて削除
+ await Promise.all((
+ await Note.find({ replyId: n._id })
+ ).map(x => deleteNote(x)));
- // この投稿のWatchをすべて削除
+ // このNoteのRenoteをすべて削除
+ await Promise.all((
+ await Note.find({ renoteId: n._id })
+ ).map(x => deleteNote(x)));
- // この投稿のReactionをすべて削除
+ // この投稿に対するNoteWatchingをすべて削除
+ await Promise.all((
+ await NoteWatching.find({ noteId: n._id })
+ ).map(x => deleteNoteWatching(x)));
+
+ // この投稿に対するNoteReactionをすべて削除
+ await Promise.all((
+ await NoteReaction.find({ noteId: n._id })
+ ).map(x => deleteNoteReaction(x)));
// この投稿に対するFavoriteをすべて削除
+ await Promise.all((
+ await Favorite.find({ noteId: n._id })
+ ).map(x => deleteFavorite(x)));
+
+ // このNoteを削除
+ await Note.remove({
+ _id: n._id
+ });
}
/**
diff --git a/src/models/user.ts b/src/models/user.ts
index cdf9a564fc..b1a68b0827 100644
--- a/src/models/user.ts
+++ b/src/models/user.ts
@@ -2,11 +2,15 @@ import * as mongo from 'mongodb';
import deepcopy = require('deepcopy');
import rap from '@prezzemolo/rap';
import db from '../db/mongodb';
-import Note, { INote, pack as packNote, physicalDelete as physicalDeleteNote } from './note';
+import Note, { INote, pack as packNote, deleteNote } from './note';
import Following from './following';
import Mute from './mute';
import getFriends from '../server/api/common/get-friends';
import config from '../config';
+import AccessToken, { deleteAccessToken } from './access-token';
+import NoteWatching, { deleteNoteWatching } from './note-watching';
+import Favorite, { deleteFavorite } from './favorite';
+import NoteReaction, { deleteNoteReaction } from './note-reaction';
const User = db.get<IUser>('users');
@@ -122,8 +126,10 @@ export function init(user): IUser {
return user;
}
-// TODO
-export async function physicalDelete(user: string | mongo.ObjectID | IUser) {
+/**
+ * Userを物理削除します
+ */
+export async function deleteUser(user: string | mongo.ObjectID | IUser) {
let u: IUser;
// Populate
@@ -141,17 +147,40 @@ export async function physicalDelete(user: string | mongo.ObjectID | IUser) {
if (u == null) return;
- // このユーザーが行った投稿をすべて削除
- const notes = await Note.find({ userId: u._id });
- await Promise.all(notes.map(n => physicalDeleteNote(n)));
+ // このユーザーのAccessTokenをすべて削除
+ await Promise.all((
+ await AccessToken.find({ userId: u._id })
+ ).map(x => deleteAccessToken(x)));
+
+ // このユーザーのNoteをすべて削除
+ await Promise.all((
+ await Note.find({ userId: u._id })
+ ).map(x => deleteNote(x)));
+
+ // このユーザーのNoteReactionをすべて削除
+ await Promise.all((
+ await NoteReaction.find({ userId: u._id })
+ ).map(x => deleteNoteReaction(x)));
+
+ // このユーザーのNoteWatchingをすべて削除
+ await Promise.all((
+ await NoteWatching.find({ userId: u._id })
+ ).map(x => deleteNoteWatching(x)));
+
+ // このユーザーのFavoriteをすべて削除
+ await Promise.all((
+ await Favorite.find({ userId: u._id })
+ ).map(x => deleteFavorite(x)));
+
+ // このユーザーのMessageをすべて削除
- // このユーザーのお気に入りをすべて削除
+ // このユーザーへのMessageをすべて削除
- // このユーザーが行ったメッセージをすべて削除
+ // このユーザーのDriveFileをすべて削除
- // このユーザーのドライブのファイルをすべて削除
+ // このユーザーのFollowingをすべて削除
- // このユーザーに関するfollowingをすべて削除
+ // このユーザーへのFollowingをすべて削除
// このユーザーを削除
}