summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-24 10:08:15 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-24 10:08:15 +0900
commit03c824f89348f39447a2240980b80095eeb34d3a (patch)
tree9931b0f548f29df655aea5ce5c93da5f0f4cb5b2 /src
parentRefactor (diff)
downloadmisskey-03c824f89348f39447a2240980b80095eeb34d3a.tar.gz
misskey-03c824f89348f39447a2240980b80095eeb34d3a.tar.bz2
misskey-03c824f89348f39447a2240980b80095eeb34d3a.zip
wip
Diffstat (limited to 'src')
-rw-r--r--src/models/user-list.ts40
-rw-r--r--src/models/user.ts15
2 files changed, 55 insertions, 0 deletions
diff --git a/src/models/user-list.ts b/src/models/user-list.ts
new file mode 100644
index 0000000000..66e2afe213
--- /dev/null
+++ b/src/models/user-list.ts
@@ -0,0 +1,40 @@
+import * as mongo from 'mongodb';
+import db from '../db/mongodb';
+
+const UserList = db.get<IUserList>('userList');
+export default UserList;
+
+export interface IUserList {
+ _id: mongo.ObjectID;
+ createdAt: Date;
+ title: string;
+ userId: mongo.ObjectID;
+ userIds: mongo.ObjectID[];
+}
+
+/**
+ * UserListを物理削除します
+ */
+export async function deleteUserList(userList: string | mongo.ObjectID | IUserList) {
+ let u: IUserList;
+
+ // Populate
+ if (mongo.ObjectID.prototype.isPrototypeOf(userList)) {
+ u = await UserList.findOne({
+ _id: userList
+ });
+ } else if (typeof userList === 'string') {
+ u = await UserList.findOne({
+ _id: new mongo.ObjectID(userList)
+ });
+ } else {
+ u = userList as IUserList;
+ }
+
+ if (u == null) return;
+
+ // このUserListを削除
+ await UserList.remove({
+ _id: u._id
+ });
+}
diff --git a/src/models/user.ts b/src/models/user.ts
index ca1ca28937..44f41d22fa 100644
--- a/src/models/user.ts
+++ b/src/models/user.ts
@@ -20,6 +20,7 @@ import FollowingLog, { deleteFollowingLog } from './following-log';
import FollowedLog, { deleteFollowedLog } from './followed-log';
import SwSubscription, { deleteSwSubscription } from './sw-subscription';
import Notification, { deleteNotification } from './notification';
+import UserList, { deleteUserList } from './user-list';
const User = db.get<IUser>('users');
@@ -260,6 +261,20 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
await Notification.find({ notifierId: u._id })
).map(x => deleteNotification(x)));
+ // このユーザーのUserListをすべて削除
+ await Promise.all((
+ await UserList.find({ userId: u._id })
+ ).map(x => deleteUserList(x)));
+
+ // このユーザーの入っているすべてのUserListからこのユーザーを削除
+ await Promise.all((
+ await UserList.find({ userIds: u._id })
+ ).map(x =>
+ UserList.update({ _id: x._id }, {
+ $pull: { userIds: u._id }
+ })
+ ));
+
// このユーザーを削除
await User.remove({
_id: u._id