diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-05-31 18:08:47 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-05-31 18:08:47 +0900 |
| commit | 9599a3123987b94def83c5d70e7dd4ddcc6bf649 (patch) | |
| tree | a333526a87c8d8cc677751b88920a743d89be4be /src/models | |
| parent | Merge pull request #1668 from syuilo/l10n_master (diff) | |
| download | misskey-9599a3123987b94def83c5d70e7dd4ddcc6bf649.tar.gz misskey-9599a3123987b94def83c5d70e7dd4ddcc6bf649.tar.bz2 misskey-9599a3123987b94def83c5d70e7dd4ddcc6bf649.zip | |
wip
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/follow-requests.ts | 50 | ||||
| -rw-r--r-- | src/models/user.ts | 21 |
2 files changed, 71 insertions, 0 deletions
diff --git a/src/models/follow-requests.ts b/src/models/follow-requests.ts new file mode 100644 index 0000000000..0de4b8e3af --- /dev/null +++ b/src/models/follow-requests.ts @@ -0,0 +1,50 @@ +import * as mongo from 'mongodb'; +import db from '../db/mongodb'; + +const FollowRequest = db.get<IFollowRequest>('followRequests'); +FollowRequest.createIndex(['followerId', 'followeeId'], { unique: true }); +export default FollowRequest; + +export type IFollowRequest = { + _id: mongo.ObjectID; + createdAt: Date; + followeeId: mongo.ObjectID; + followerId: mongo.ObjectID; + + // 非正規化 + _followee: { + host: string; + inbox?: string; + }, + _follower: { + host: string; + inbox?: string; + } +}; + +/** + * FollowRequestを物理削除します + */ +export async function deleteFollowRequest(followRequest: string | mongo.ObjectID | IFollowRequest) { + let f: IFollowRequest; + + // Populate + if (mongo.ObjectID.prototype.isPrototypeOf(followRequest)) { + f = await FollowRequest.findOne({ + _id: followRequest + }); + } else if (typeof followRequest === 'string') { + f = await FollowRequest.findOne({ + _id: new mongo.ObjectID(followRequest) + }); + } else { + f = followRequest as IFollowRequest; + } + + if (f == null) return; + + // このFollowingを削除 + await FollowRequest.remove({ + _id: f._id + }); +} diff --git a/src/models/user.ts b/src/models/user.ts index 11eafe05ea..8dfd783a9f 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -22,6 +22,7 @@ import FollowedLog, { deleteFollowedLog } from './followed-log'; import SwSubscription, { deleteSwSubscription } from './sw-subscription'; import Notification, { deleteNotification } from './notification'; import UserList, { deleteUserList } from './user-list'; +import FollowRequest, { deleteFollowRequest } from './follow-requests'; const User = db.get<IUser>('users'); @@ -50,7 +51,17 @@ type IUserBase = { data: any; description: string; pinnedNoteId: mongo.ObjectID; + + /** + * 凍結されているか否か + */ isSuspended: boolean; + + /** + * 鍵アカウントか否か + */ + isLocked: boolean; + host: string; }; @@ -240,6 +251,16 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { await Following.find({ followeeId: u._id }) ).map(x => deleteFollowing(x))); + // このユーザーのFollowRequestをすべて削除 + await Promise.all(( + await FollowRequest.find({ followerId: u._id }) + ).map(x => deleteFollowRequest(x))); + + // このユーザーへのFollowRequestをすべて削除 + await Promise.all(( + await FollowRequest.find({ followeeId: u._id }) + ).map(x => deleteFollowRequest(x))); + // このユーザーのFollowingLogをすべて削除 await Promise.all(( await FollowingLog.find({ userId: u._id }) |