summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorこぴなたみぽ <syuilotan@yahoo.co.jp>2018-04-12 07:32:35 +0900
committerこぴなたみぽ <syuilotan@yahoo.co.jp>2018-04-12 07:32:35 +0900
commit051ab451816edfb71f54d8aa887a13633cdda187 (patch)
tree8e69f7f7a4280c99951af37da57db4339332f849 /src/models
parentwip (diff)
downloadmisskey-051ab451816edfb71f54d8aa887a13633cdda187.tar.gz
misskey-051ab451816edfb71f54d8aa887a13633cdda187.tar.bz2
misskey-051ab451816edfb71f54d8aa887a13633cdda187.zip
wip
Diffstat (limited to 'src/models')
-rw-r--r--src/models/sw-subscription.ts28
-rw-r--r--src/models/user.ts6
2 files changed, 34 insertions, 0 deletions
diff --git a/src/models/sw-subscription.ts b/src/models/sw-subscription.ts
index 743d0d2dd9..621ac8a9b6 100644
--- a/src/models/sw-subscription.ts
+++ b/src/models/sw-subscription.ts
@@ -11,3 +11,31 @@ export interface ISwSubscription {
auth: string;
publickey: string;
}
+
+/**
+ * SwSubscriptionを物理削除します
+ */
+export async function deleteSwSubscription(swSubscription: string | mongo.ObjectID | ISwSubscription) {
+ let s: ISwSubscription;
+
+ // Populate
+ if (mongo.ObjectID.prototype.isPrototypeOf(swSubscription)) {
+ s = await SwSubscription.findOne({
+ _id: swSubscription
+ });
+ } else if (typeof swSubscription === 'string') {
+ s = await SwSubscription.findOne({
+ _id: new mongo.ObjectID(swSubscription)
+ });
+ } else {
+ s = swSubscription as ISwSubscription;
+ }
+
+ if (s == null) return;
+
+ // このSwSubscriptionを削除
+ await SwSubscription.remove({
+ _id: s._id
+ });
+}
+
diff --git a/src/models/user.ts b/src/models/user.ts
index a4b7becbd2..c121790c31 100644
--- a/src/models/user.ts
+++ b/src/models/user.ts
@@ -18,6 +18,7 @@ import DriveFolder, { deleteDriveFolder } from './drive-folder';
import PollVote, { deletePollVote } from './poll-vote';
import FollowingLog, { deleteFollowingLog } from './following-log';
import FollowedLog, { deleteFollowedLog } from './followed-log';
+import SwSubscription, { deleteSwSubscription } from './sw-subscription';
const User = db.get<IUser>('users');
@@ -239,6 +240,11 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
await FollowedLog.find({ userId: u._id })
).map(x => deleteFollowedLog(x)));
+ // このユーザーのSwSubscriptionをすべて削除
+ await Promise.all((
+ await SwSubscription.find({ userId: u._id })
+ ).map(x => deleteSwSubscription(x)));
+
// このユーザーを削除
}