diff options
| author | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-26 00:19:07 +0900 |
|---|---|---|
| committer | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-26 14:07:16 +0900 |
| commit | 19b9cb105d49e2a00ae19e3dc1f2d36dc394f148 (patch) | |
| tree | 5faa9ad213bbf2efdcb4d06cf4fc941a501ab7f8 /src/api/models | |
| parent | Allow to use domain whose prefix is not misskey (diff) | |
| download | sharkey-19b9cb105d49e2a00ae19e3dc1f2d36dc394f148.tar.gz sharkey-19b9cb105d49e2a00ae19e3dc1f2d36dc394f148.tar.bz2 sharkey-19b9cb105d49e2a00ae19e3dc1f2d36dc394f148.zip | |
Introduce account document to user document
An account document is attached to a user document if an account of the
user is on the server. It may be missing if the user is on a remote server.
Diffstat (limited to 'src/api/models')
| -rw-r--r-- | src/api/models/user.ts | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/src/api/models/user.ts b/src/api/models/user.ts index ba2765c793..372e2c5dac 100644 --- a/src/api/models/user.ts +++ b/src/api/models/user.ts @@ -11,7 +11,7 @@ import config from '../../conf'; const User = db.get<IUser>('users'); User.createIndex('username'); -User.createIndex('token'); +User.createIndex('account.token'); export default User; @@ -43,46 +43,48 @@ export type IUser = { _id: mongo.ObjectID; created_at: Date; deleted_at: Date; - email: string; followers_count: number; following_count: number; - links: string[]; name: string; - password: string; posts_count: number; drive_capacity: number; username: string; username_lower: string; - token: string; avatar_id: mongo.ObjectID; banner_id: mongo.ObjectID; data: any; - twitter: { - access_token: string; - access_token_secret: string; - user_id: string; - screen_name: string; - }; - line: { - user_id: string; - }; description: string; - profile: { - location: string; - birthday: string; // 'YYYY-MM-DD' - tags: string[]; - }; - last_used_at: Date; latest_post: IPost; pinned_post_id: mongo.ObjectID; - is_bot: boolean; - is_pro: boolean; is_suspended: boolean; keywords: string[]; - two_factor_secret: string; - two_factor_enabled: boolean; - client_settings: any; - settings: any; + account: { + email: string; + links: string[]; + password: string; + token: string; + twitter: { + access_token: string; + access_token_secret: string; + user_id: string; + screen_name: string; + }; + line: { + user_id: string; + }; + profile: { + location: string; + birthday: string; // 'YYYY-MM-DD' + tags: string[]; + }; + last_used_at: Date; + is_bot: boolean; + is_pro: boolean; + two_factor_secret: string; + two_factor_enabled: boolean; + client_settings: any; + settings: any; + }; }; export function init(user): IUser { @@ -119,11 +121,11 @@ export const pack = ( const fields = opts.detail ? { } : { - settings: false, - client_settings: false, - profile: false, - keywords: false, - domains: false + 'account.settings': false, + 'account.client_settings': false, + 'account.profile': false, + 'account.keywords': false, + 'account.domains': false }; // Populate the user if 'user' is ID @@ -158,26 +160,26 @@ export const pack = ( delete _user.latest_post; // Remove private properties - delete _user.password; - delete _user.token; - delete _user.two_factor_temp_secret; - delete _user.two_factor_secret; + delete _user.account.password; + delete _user.account.token; + delete _user.account.two_factor_temp_secret; + delete _user.account.two_factor_secret; delete _user.username_lower; - if (_user.twitter) { - delete _user.twitter.access_token; - delete _user.twitter.access_token_secret; + if (_user.account.twitter) { + delete _user.account.twitter.access_token; + delete _user.account.twitter.access_token_secret; } - delete _user.line; + delete _user.account.line; // Visible via only the official client if (!opts.includeSecrets) { - delete _user.email; - delete _user.settings; - delete _user.client_settings; + delete _user.account.email; + delete _user.account.settings; + delete _user.account.client_settings; } if (!opts.detail) { - delete _user.two_factor_enabled; + delete _user.account.two_factor_enabled; } _user.avatar_url = _user.avatar_id != null |